Skip to content

Commit

Permalink
fix:throw an error for invaild json string
Browse files Browse the repository at this point in the history
  • Loading branch information
ni00 committed Dec 7, 2023
1 parent 6f146f1 commit 72f75ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
13 changes: 9 additions & 4 deletions cli/src/utils/jsonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ export const jsonParse: typeof JSON.parse = (...args: any[]) => {
try {
// When JSON only contains integers, use the native bigint type.
return JSONBigInt.parse(...args)
} catch (_error) {
// When JSON contains floating-point numbers, use the bignumber library.
// The numbers in the parsed JSON Object will be represented as BigNumber Objects.
return JSONBigNumber.parse(...args)
} catch {
try {
// When JSON contains floating-point numbers, use the bignumber library.
// The numbers in the parsed JSON Object will be represented as BigNumber Objects.
return JSONBigNumber.parse(...args)
} catch {
// To verify the validity of the JSON string and throw an error if it's invalid.
return JSON.parse(args[0], args[1])
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/utils/jsonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ export const jsonParse: typeof JSON.parse = (...args: any[]) => {
try {
// When JSON only contains integers, use the native bigint type.
return JSONBigInt.parse(...args)
} catch (_error) {
// When JSON contains floating-point numbers, use the bignumber library.
// The numbers in the parsed JSON Object will be represented as BigNumber Objects.
return JSONBigNumber.parse(...args)
} catch {
try {
// When JSON contains floating-point numbers, use the bignumber library.
// The numbers in the parsed JSON Object will be represented as BigNumber Objects.
return JSONBigNumber.parse(...args)
} catch {
// To verify the validity of the JSON string and throw an error if it's invalid.
return JSON.parse(args[0], args[1])
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions web/src/utils/jsonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ export const jsonParse: typeof JSON.parse = (...args: any[]) => {
try {
// When JSON only contains integers, use the native bigint type.
return JSONBigInt.parse(...args)
} catch (_error) {
// When JSON contains floating-point numbers, use the bignumber library.
// The numbers in the parsed JSON Object will be represented as BigNumber Objects.
return JSONBigNumber.parse(...args)
} catch {
try {
// When JSON contains floating-point numbers, use the bignumber library.
// The numbers in the parsed JSON Object will be represented as BigNumber Objects.
return JSONBigNumber.parse(...args)
} catch {
// To verify the validity of the JSON string and throw an error if it's invalid.
return JSON.parse(args[0], args[1])
}
}
}

Expand Down

0 comments on commit 72f75ce

Please sign in to comment.