summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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();
+});