mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibJS: Treat '\\' as an escaped character in template literals
Before this change we would ignore that the second backslash is escaped and template strings ending with ` \\` would be unterminated as the second slash was used to escape the closing quote.
This commit is contained in:
parent
8e624c8f6d
commit
b3edd94869
Notes:
sideshowbarker
2024-07-17 04:27:29 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/b3edd94869 Pull-request: https://github.com/SerenityOS/serenity/pull/16073 Issue: https://github.com/SerenityOS/serenity/issues/16044 Reviewed-by: https://github.com/linusg
2 changed files with 11 additions and 1 deletions
|
@ -610,8 +610,15 @@ Token Lexer::next()
|
|||
consume();
|
||||
m_template_states.last().in_expr = true;
|
||||
} else {
|
||||
// TemplateCharacter ::
|
||||
// $ [lookahead ≠ {]
|
||||
// \ TemplateEscapeSequence
|
||||
// \ NotEscapeSequence
|
||||
// LineContinuation
|
||||
// LineTerminatorSequence
|
||||
// SourceCharacter but not one of ` or \ or $ or LineTerminator
|
||||
while (!match('$', '{') && m_current_char != '`' && !is_eof()) {
|
||||
if (match('\\', '$') || match('\\', '`'))
|
||||
if (match('\\', '$') || match('\\', '`') || match('\\', '\\'))
|
||||
consume();
|
||||
consume();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ test("plain literals with expression-like characters", () => {
|
|||
|
||||
test("plain literals with escaped special characters", () => {
|
||||
expect(`foo\``).toBe("foo`");
|
||||
expect(`foo\\`).toBe("foo\\");
|
||||
expect(`foo\\\``).toBe("foo\\`");
|
||||
expect(`foo\\\\`).toBe("foo\\\\");
|
||||
expect(`foo\$`).toBe("foo$");
|
||||
expect(`foo \${"bar"}`).toBe('foo ${"bar"}');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue