diff options
author | davidot <davidot@serenityos.org> | 2021-11-26 23:26:42 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-30 17:05:32 +0000 |
commit | 7624c3de0e2cb4bce171a3524cdbc070257ef93c (patch) | |
tree | 7ebee28cb87769e0845631fec44a18752a20d4a6 /Userland/Libraries/LibJS | |
parent | c57721cf836aa76f21fb6d18ad47ddda0429c8fa (diff) | |
download | serenity-7624c3de0e2cb4bce171a3524cdbc070257ef93c.zip |
LibJS: Disallow '\8' and '\9' in strict mode due to being octal escapes
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/string-escapes.js | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Token.cpp | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/string-escapes.js b/Userland/Libraries/LibJS/Tests/string-escapes.js index 64a81b1fe1..9b45d08588 100644 --- a/Userland/Libraries/LibJS/Tests/string-escapes.js +++ b/Userland/Libraries/LibJS/Tests/string-escapes.js @@ -62,4 +62,11 @@ describe("octal escapes", () => { // Because of the non string statement in the middle strict mode is not enabled. expect("'\\123'; somethingElse; 'use strict'").toEval(); }); + + test("invalid octal escapes fail in strict mode", () => { + expect("'use strict'; '\\8'").not.toEval(); + expect("'use strict'; '\\800'").not.toEval(); + expect("'use strict'; '\\9'").not.toEval(); + expect("'use strict'; '\\912'").not.toEval(); + }); }); diff --git a/Userland/Libraries/LibJS/Token.cpp b/Userland/Libraries/LibJS/Token.cpp index 16f0a00443..9a51a15508 100644 --- a/Userland/Libraries/LibJS/Token.cpp +++ b/Userland/Libraries/LibJS/Token.cpp @@ -198,6 +198,12 @@ String Token::string_value(StringValueStatus& status) const continue; } + if (lexer.next_is('8') || lexer.next_is('9')) { + status = StringValueStatus::LegacyOctalEscapeSequence; + builder.append(lexer.consume()); + continue; + } + lexer.retreat(); builder.append(lexer.consume_escaped_character('\\', "b\bf\fn\nr\rt\tv\v")); } |