summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-10-27 19:30:27 +0000
committerAndreas Kling <kling@serenityos.org>2020-10-28 21:11:32 +0100
commitb5bd05b71732ebfdbd1e94571e717be885d9e458 (patch)
tree467ecde56b88eb9a0e520a4555a8e70f25411677
parentb4e51249e95ca891dad26c3763788c85d54903e5 (diff)
downloadserenity-b5bd05b71732ebfdbd1e94571e717be885d9e458.zip
LibJS: Don't parse numeric literal containing 8 or 9 as octal
If the value has a leading zero (allowed in non-strict mode) but contains the digits 8 or 9 it can't be an octal number.
-rw-r--r--Libraries/LibJS/Tests/numeric-literals-basic.js1
-rw-r--r--Libraries/LibJS/Token.cpp3
2 files changed, 3 insertions, 1 deletions
diff --git a/Libraries/LibJS/Tests/numeric-literals-basic.js b/Libraries/LibJS/Tests/numeric-literals-basic.js
index f226581320..b4b9f75181 100644
--- a/Libraries/LibJS/Tests/numeric-literals-basic.js
+++ b/Libraries/LibJS/Tests/numeric-literals-basic.js
@@ -10,6 +10,7 @@ test("octal literals", () => {
expect(0o10).toBe(8);
expect(0o10).toBe(8);
expect(010).toBe(8);
+ expect(089).toBe(89);
});
test("binary literals", () => {
diff --git a/Libraries/LibJS/Token.cpp b/Libraries/LibJS/Token.cpp
index 082e8ac9aa..2826f7fbf6 100644
--- a/Libraries/LibJS/Token.cpp
+++ b/Libraries/LibJS/Token.cpp
@@ -86,7 +86,8 @@ double Token::double_value() const
return static_cast<double>(strtoul(value_string.characters() + 2, nullptr, 2));
} else if (isdigit(value_string[1])) {
// also octal, but syntax error in strict mode
- return static_cast<double>(strtoul(value_string.characters() + 1, nullptr, 8));
+ if (!m_value.contains('8') && !m_value.contains('9'))
+ return static_cast<double>(strtoul(value_string.characters() + 1, nullptr, 8));
}
}
return strtod(value_string.characters(), nullptr);