-
-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSON.parse(): bail if we don't get a string key (in non-relaxed mode)
- Loading branch information
1 parent
693bd55
commit 7186d4c
Showing
2 changed files
with
22 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
// JSON shouldn't print stuff like __proto__ and constructor | ||
|
||
function A() {} | ||
function A() {} | ||
var a = new A(); | ||
|
||
result = JSON.stringify(a)=="{}"; | ||
|
||
function assertEq(a, b) { | ||
if (typeof a === "object") | ||
// note: doesn't check keys in b | ||
for (var k in a) | ||
assertEq(a[k], b[k]); | ||
else if (a !== b) | ||
throw new Error("mismatch, " + a + " != " + b); | ||
} | ||
|
||
// no exceptions thrown: | ||
assertEq(JSON.parse('{"a": 1}'), {"a": 1}); | ||
assertEq(JSON.parse('["4", 5, "six"]'), ["4", 5, "six"]); | ||
assertEq(JSON.parse('["4", 5, "six", {"x": 5}]'), ["4", 5, "six", {"x": 5}]); | ||
assertEq(JSON.parse('""'), ""); | ||
assertEq(JSON.parse('5'), 5); | ||
assertEq(JSON.parse('[]'), []); | ||
assertEq(JSON.parse('{}'), {}); |