File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -599,6 +599,17 @@ export class Marshaller implements IMarshaller {
599599 return this . marshalFromStringToBestGuess ( stringified ) ;
600600 }
601601
602+ /**
603+ * If the string starts with a number but should be a string nevertheless, this method returns true.
604+ * @param {string } value
605+ * @returns {boolean }
606+ */
607+ private startsWithNumberButShouldEnforceString ( value : string ) : boolean {
608+ // If the value starts with a digit and possibly a '.' character but then goes on with something
609+ // else, enforce a string.
610+ return / ^ \d + [ . ] * [ ^ \d . ] + / . test ( value . trim ( ) ) ;
611+ }
612+
602613 /**
603614 * Parses the string and and marshals it into the most fitting type based on heuristics.
604615 * @param {string } data
@@ -617,7 +628,10 @@ export class Marshaller implements IMarshaller {
617628
618629 // It might be a number.
619630 const toNum = Number . parseFloat ( primitive ) ;
620- if ( ! isNaN ( toNum ) ) return toNum ;
631+ if ( ! isNaN ( toNum ) ) {
632+ if ( this . startsWithNumberButShouldEnforceString ( primitive ) ) return primitive ;
633+ return toNum ;
634+ }
621635
622636 // It might be an array
623637 if ( primitive . startsWith ( "[" ) && primitive . endsWith ( "]" ) ) return JSON . parse ( primitive ) ;
You can’t perform that action at this time.
0 commit comments