@@ -965,13 +965,13 @@ export class Marshaller implements IMarshaller {
965965 return toNum ;
966966 }
967967
968- const asObj = this . attemptStringToObjectConversion ( primitive ) ;
969- if ( asObj != null ) return asObj ;
970-
971968 if ( Marshaller . FUNCTION_REGEX_1 . test ( primitive . trim ( ) ) ) return new Function ( `return ${ primitive } ` ) ( ) ;
972969 if ( Marshaller . FUNCTION_REGEX_2 . test ( primitive . trim ( ) ) ) return new Function ( `return ${ primitive } ` ) ( ) ;
973970 if ( Marshaller . FUNCTION_REGEX_3 . test ( primitive . trim ( ) ) ) return new Function ( `return ${ primitive } ` ) ( ) ;
974971
972+ const asObj = this . attemptStringToObjectConversion ( primitive ) ;
973+ if ( asObj != null ) return asObj ;
974+
975975 try {
976976 return JSON . parse ( primitive ) ;
977977 } catch ( e ) {
@@ -1022,25 +1022,19 @@ export class Marshaller implements IMarshaller {
10221022 /**
10231023 * Attempts to convert a string into a regular object. Returns null if it fails.
10241024 * @param {string } primitive
1025- * @param {number } [attempt=0]
10261025 * @returns {object|null }
10271026 */
1028- private attemptStringToObjectConversion ( primitive : string , attempt : number = 0 ) : { [ key : string ] : string } | null {
1027+ private attemptStringToObjectConversion ( primitive : string ) : { [ key : string ] : string } | null {
10291028 try {
10301029 return JSON . parse ( primitive ) ;
10311030 } catch ( e ) {
1032-
1033- if ( attempt === 0 ) {
1034- // Try to format the string so it fits the JSON standard.
1035- let trimmed = primitive
1036- . replace ( / ( [ { , : } " \] ] ) ( [ \t \r \n ] * ) / g, ( _ , p1 ) => `${ p1 } ` )
1037- . replace ( / ( [ { , ] ) ( \w + ) ( : ) / g, ( _ , p1 , p2 , p3 ) => `${ p1 } "${ p2 } "${ p3 } ` )
1038- . replace ( / ` ( [ ^ ` ] * ) ` / g, ( _ , p1 ) => `"${ p1 } "` )
1039- . trim ( ) ;
1040- if ( trimmed . endsWith ( ";" ) ) trimmed = trimmed . slice ( 0 , trimmed . length - 1 ) ;
1041- return this . attemptStringToObjectConversion ( trimmed , ++ attempt ) ;
1031+ try {
1032+ const evaluated = new Function ( `return (${ primitive } )` ) ( ) ;
1033+ if ( this . typeDetector . isObject ( evaluated ) ) return < { [ key : string ] : string } > evaluated ;
1034+ return null ;
1035+ } catch ( e ) {
1036+ return null ;
10421037 }
1043- return null ;
10441038 }
10451039 }
10461040
0 commit comments