summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2021-06-18 16:21:52 +0000
committerLinus Groh <mail@linusgroh.de>2021-06-18 19:18:15 +0100
commitc5073cb2879843528a5c8127f80aaea0bc5d4066 (patch)
tree6089108a9481101161fb88f74e1b723da48e938f /Userland
parent3abcfcc1785c13da29d205376f700084fead88be (diff)
downloadserenity-c5073cb2879843528a5c8127f80aaea0bc5d4066.zip
LibJS: Do not trim whitespace from property names when they're numbers
Fixes #7803.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/PropertyName.h2
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Array/array-index-number-whitespace.js7
2 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/PropertyName.h b/Userland/Libraries/LibJS/Runtime/PropertyName.h
index 42278ae62b..162059948d 100644
--- a/Userland/Libraries/LibJS/Runtime/PropertyName.h
+++ b/Userland/Libraries/LibJS/Runtime/PropertyName.h
@@ -111,7 +111,7 @@ public:
bool try_coerce_into_number()
{
VERIFY(m_string_may_be_number);
- i32 property_index = m_string.to_int().value_or(-1);
+ i32 property_index = m_string.to_int(TrimWhitespace::No).value_or(-1);
if (property_index < 0) {
m_string_may_be_number = false;
return false;
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Array/array-index-number-whitespace.js b/Userland/Libraries/LibJS/Tests/builtins/Array/array-index-number-whitespace.js
new file mode 100644
index 0000000000..d45cf6dd58
--- /dev/null
+++ b/Userland/Libraries/LibJS/Tests/builtins/Array/array-index-number-whitespace.js
@@ -0,0 +1,7 @@
+test("indexing the array doesn't strip whitespace if it's a number", () => {
+ var a = [];
+ a[1] = 1;
+
+ expect(a["1"]).toBe(1);
+ expect(a[" 1 "]).toBeUndefined();
+});