1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

AK: Treat empty string as invalid JSON

Previously we would treat the empty string as `null`. This caused
JavaScript like this to fail:
```js
var object = {};
try {
    object = JSON.parse("");
} catch {}
var array = object.array || [];
```
Since `JSON.parse("")` returned null instead of throwing, it would set
`object` to null and then try and use it instead of using the default
backup value.
This commit is contained in:
Luke Wilde 2022-07-10 21:37:28 +01:00 committed by Linus Groh
parent 36c3a0fac2
commit da25ac0d48
3 changed files with 2 additions and 3 deletions

View file

@ -29,6 +29,7 @@ test("syntax errors", () => {
"[1,2,3, ]",
'{ "foo": "bar",}',
'{ "foo": "bar", }',
"",
].forEach(test => {
expect(() => {
JSON.parse(test);