Pārlūkot izejas kodu

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.
Linus Groh 4 gadi atpakaļ
vecāks
revīzija
b5bd05b717

+ 1 - 0
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", () => {

+ 2 - 1
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);