diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-07-10 21:37:28 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-10 23:31:48 +0200 |
commit | da25ac0d48e728cb424f1fce7f266563ec6f96b0 (patch) | |
tree | 7e1d6c45561163c0263d1ea7da558eedb9a22650 /Userland/Libraries/LibJS | |
parent | 36c3a0fac28dd65ef91ac8604abdc10f5fd0bdba (diff) | |
download | serenity-da25ac0d48e728cb424f1fce7f266563ec6f96b0.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js b/Userland/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js index a05e579e2a..ff4d4bd30e 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js +++ b/Userland/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js @@ -29,6 +29,7 @@ test("syntax errors", () => { "[1,2,3, ]", '{ "foo": "bar",}', '{ "foo": "bar", }', + "", ].forEach(test => { expect(() => { JSON.parse(test); |