1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibJS: Do not trim whitespace from property names when they're numbers

Fixes #7803.
This commit is contained in:
sin-ack 2021-06-18 16:21:52 +00:00 committed by Linus Groh
parent 3abcfcc178
commit c5073cb287
2 changed files with 8 additions and 1 deletions

View file

@ -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;

View file

@ -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();
});