Skip to content

Commit 2e44954

Browse files
committed
fix Safari 9 JSON.parse bug with handling negative zero + some whitespaces
1 parent 2af87cc commit 2e44954

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- `Number.range` Stage 1 proposal and method [renamed to `Iterator.range`](https://github.com/tc39/proposal-Number.range)
3131
- `Function.prototype.unThis` Stage 0 proposal and method [renamed to `Function.prototype.demethodize`](https://github.com/js-choi/proposal-function-demethodize)
3232
- Improved some cases handling of array-replacer in `JSON.stringify` symbols handling fix
33-
- 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.)
33+
- 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.)
3434
- Fixed configurability and `ToString` conversion of some accessors
3535
- Added Opera Android 73 compat data mapping
3636
- Added TypeScript definitions to `core-js-builder`

packages/core-js/modules/esnext.json.parse.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,22 @@ Context.prototype = {
240240
var NO_SOURCE_SUPPORT = fails(function () {
241241
var unsafeInt = '9007199254740993';
242242
var source;
243-
JSON.parse(unsafeInt, function (key, value, context) {
243+
nativeParse(unsafeInt, function (key, value, context) {
244244
source = context.source;
245245
});
246246
return source !== unsafeInt;
247247
});
248248

249+
var PROPER_BASE_PARSE = NATIVE_SYMBOL && !fails(function () {
250+
// Safari 9 bug
251+
return 1 / nativeParse('-0 \t') !== -Infinity;
252+
});
253+
249254
// `JSON.parse` method
250255
// https://tc39.es/ecma262/#sec-json.parse
251256
// https://github.com/tc39/proposal-json-parse-with-source
252257
$({ target: 'JSON', stat: true, forced: NO_SOURCE_SUPPORT }, {
253258
parse: function parse(text, reviver) {
254-
return NATIVE_SYMBOL && nativeParse && !isCallable(reviver) ? nativeParse(text) : $parse(text, reviver);
259+
return PROPER_BASE_PARSE && !isCallable(reviver) ? nativeParse(text) : $parse(text, reviver);
255260
}
256261
});

0 commit comments

Comments
 (0)