@@ -4,7 +4,14 @@ import { Utility } from "./Utility";
44import { Config , HeaderCollection } from "../dynamics-web-api" ;
55import { ErrorHelper } from "../helpers/ErrorHelper" ;
66import { InternalConfig } from "./Config" ;
7- import { safelyRemoveCurlyBracketsFromUrl } from "../helpers/Regex" ;
7+ import {
8+ removeCurlyBracketsFromUuid ,
9+ removeLeadingSlash ,
10+ escapeUnicodeSymbols ,
11+ safelyRemoveCurlyBracketsFromUrl ,
12+ SEARCH_FOR_ENTITY_NAME_REGEX ,
13+ removeDoubleQuotes ,
14+ } from "../helpers/Regex" ;
815
916export let entityNames : Record < string , string | null > | null = null ;
1017
@@ -339,9 +346,9 @@ export const composePreferHeader = (request: InternalRequest, config: Config): s
339346 if ( trimmedItem === "return=representation" ) {
340347 returnRepresentation = true ;
341348 } else if ( trimmedItem . includes ( "odata.include-annotations=" ) ) {
342- includeAnnotations = trimmedItem . replace ( "odata.include-annotations=" , "" ) . replace ( / " / g , "" ) ;
349+ includeAnnotations = removeDoubleQuotes ( trimmedItem . replace ( "odata.include-annotations=" , "" ) ) ;
343350 } else if ( trimmedItem . startsWith ( "odata.maxpagesize=" ) ) {
344- maxPageSize = Number ( trimmedItem . replace ( "odata.maxpagesize=" , "" ) . replace ( / " / g , "" ) ) || 0 ;
351+ maxPageSize = Number ( removeDoubleQuotes ( trimmedItem . replace ( "odata.maxpagesize=" , "" ) ) ) || 0 ;
345352 } else if ( trimmedItem . includes ( "odata.track-changes" ) ) {
346353 trackChanges = true ;
347354 } else if ( trimmedItem . includes ( "odata.continue-on-error" ) ) {
@@ -491,15 +498,12 @@ export const processData = (data: any, config: InternalConfig): string | Uint8Ar
491498
492499 if ( data instanceof Uint8Array || data instanceof Uint16Array || data instanceof Uint32Array ) return data ;
493500
494- const replaceGuidBrackets = ( value : string ) : string => value . replace ( / ( .+ ) \( \{ ( [ \w \d - ] + ) \} \) / g, "$1($2)" ) ;
495-
496501 const replaceEntityNameWithCollectionName = ( value : string ) : string => {
497- const regularExpression = / ( [ \w _ ] + ) ( \( [ \d \w - ] + \) ) $ / ;
498- const valueParts = regularExpression . exec ( value ) ;
502+ const valueParts = SEARCH_FOR_ENTITY_NAME_REGEX . exec ( value ) ;
499503 if ( valueParts && valueParts . length > 2 ) {
500504 const collectionName = findCollectionName ( valueParts [ 1 ] ) ;
501505 if ( ! Utility . isNull ( collectionName ) ) {
502- return value . replace ( regularExpression , `${ collectionName } $2` ) ;
506+ return value . replace ( SEARCH_FOR_ENTITY_NAME_REGEX , `${ collectionName } $2` ) ;
503507 }
504508 }
505509 return value ;
@@ -512,7 +516,7 @@ export const processData = (data: any, config: InternalConfig): string | Uint8Ar
512516 value = `/${ value } ` ;
513517 }
514518 } else {
515- value = `${ config . dataApi . url } ${ value . replace ( / ^ \/ / , "" ) } ` ;
519+ value = `${ config . dataApi . url } ${ removeLeadingSlash ( value ) } ` ;
516520 }
517521 }
518522 return value ;
@@ -521,7 +525,7 @@ export const processData = (data: any, config: InternalConfig): string | Uint8Ar
521525 const stringifiedData = JSON . stringify ( data , ( key , value ) => {
522526 if ( key . endsWith ( "@odata.bind" ) || key . endsWith ( "@odata.id" ) ) {
523527 if ( typeof value === "string" && ! value . startsWith ( "$" ) ) {
524- value = replaceGuidBrackets ( value ) ;
528+ value = removeCurlyBracketsFromUuid ( value ) ;
525529 if ( config . useEntityNames ) {
526530 value = replaceEntityNameWithCollectionName ( value ) ;
527531 }
@@ -533,7 +537,7 @@ export const processData = (data: any, config: InternalConfig): string | Uint8Ar
533537 return value ;
534538 } ) ;
535539
536- return stringifiedData . replace ( / [ \u007F - \uFFFF ] / g , ( chr : string ) => `\\u ${ ( "0000" + chr . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 4 ) } ` ) ;
540+ return escapeUnicodeSymbols ( stringifiedData ) ;
537541} ;
538542
539543export const setStandardHeaders = ( headers : HeaderCollection = { } ) : HeaderCollection => {
0 commit comments