Skip to content

Commit

Permalink
fix: use JsonSigRx to also match numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed May 27, 2020
1 parent 7bc70cf commit 3023552
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.ts
Expand Up @@ -6,6 +6,8 @@ export type JSONValue = true | false | null | string | Number | JSONObject | JSO
const suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/
const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/

const JsonSigRx = /^["{[].*|^-?[0-9][0-9.]+$/

function jsonParseTransform (key: string, value: any): any {
if (key === '__proto__' || key === 'constructor') {
return
Expand All @@ -26,7 +28,7 @@ export default function destr (val: string | any): JSONValue | undefined {
if (_lval === 'infinity') { return Infinity }
if (_lval === 'undefined') { return undefined }

if (val[0] !== '"' && val[0] !== '{' && val[0] !== '[') {
if (!JsonSigRx.test(val)) {
return val
}

Expand Down

0 comments on commit 3023552

Please sign in to comment.