summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorserenitydev <ben.d.abraham@gmail.com>2022-02-11 03:29:08 -0500
committerTim Flynn <trflynn89@pm.me>2022-02-16 07:22:51 -0500
commit23c72c67285743c9815f7ea82bd35b94aa179893 (patch)
tree11ebcf2ee9842d6692e61df18f003a2f0e85a63d /Userland
parentaf75503c173b974b368307bb3fdc974b620d76d1 (diff)
downloadserenity-23c72c67285743c9815f7ea82bd35b94aa179893.zip
AK: Fix userland parsing of rounded floating point numbers
Parse JSON floating point literals properly, No longer throwing a SyntaxError when the decimal portion of the number exceeds the capacity of u32. Added tests to AK/TestJSON and LibJS/builtins/JSON/JSON.parse
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js7
1 files changed, 7 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 6cc501f51a..a05e579e2a 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/JSON/JSON.parse.js
@@ -43,3 +43,10 @@ test("negative zero", () => {
expect(JSON.parse(-0)).toEqual(0);
});
+
+// The underlying parser resolves decimal numbers by storing the decimal portion in an integer
+// This test handles a regression where the decimal portion was only using a u32 vs. u64
+// and would fail to parse.
+test("long decimal parse", () => {
+ expect(JSON.parse("1644452550.6489999294281")).toEqual(1644452550.6489999294281);
+});