Skip to content

Commit

Permalink
fix Safari 9 JSON.parse bug with handling negative zero + some whit…
Browse files Browse the repository at this point in the history
…espaces
  • Loading branch information
zloirock committed Feb 10, 2023
1 parent 2af87cc commit 2e44954
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- `Number.range` Stage 1 proposal and method [renamed to `Iterator.range`](https://github.com/tc39/proposal-Number.range)
- `Function.prototype.unThis` Stage 0 proposal and method [renamed to `Function.prototype.demethodize`](https://github.com/js-choi/proposal-function-demethodize)
- Improved some cases handling of array-replacer in `JSON.stringify` symbols handling fix
- Fixed many other old `JSON.{ parse, stringify }` bugs (numbers instead of strings as keys in replacer, handling negative zeroes, some more handling symbols cases, etc.)
- Fixed many other old `JSON.{ parse, stringify }` bugs (numbers instead of strings as keys in replacer, handling negative zeroes, spaces, some more handling symbols cases, etc.)
- Fixed configurability and `ToString` conversion of some accessors
- Added Opera Android 73 compat data mapping
- Added TypeScript definitions to `core-js-builder`
Expand Down
9 changes: 7 additions & 2 deletions packages/core-js/modules/esnext.json.parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,22 @@ Context.prototype = {
var NO_SOURCE_SUPPORT = fails(function () {
var unsafeInt = '9007199254740993';
var source;
JSON.parse(unsafeInt, function (key, value, context) {
nativeParse(unsafeInt, function (key, value, context) {
source = context.source;
});
return source !== unsafeInt;
});

var PROPER_BASE_PARSE = NATIVE_SYMBOL && !fails(function () {
// Safari 9 bug
return 1 / nativeParse('-0 \t') !== -Infinity;
});

// `JSON.parse` method
// https://tc39.es/ecma262/#sec-json.parse
// https://github.com/tc39/proposal-json-parse-with-source
$({ target: 'JSON', stat: true, forced: NO_SOURCE_SUPPORT }, {
parse: function parse(text, reviver) {
return NATIVE_SYMBOL && nativeParse && !isCallable(reviver) ? nativeParse(text) : $parse(text, reviver);
return PROPER_BASE_PARSE && !isCallable(reviver) ? nativeParse(text) : $parse(text, reviver);
}
});

0 comments on commit 2e44954

Please sign in to comment.