From ea08bf581260e51d5a5929d7db89472dec79dd04 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 29 Nov 2020 22:59:06 +0000 Subject: [PATCH] LibJS: Fix crash in Lexer on EOF in unterminated template literal Fixes #4252. --- Libraries/LibJS/Lexer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/LibJS/Lexer.cpp b/Libraries/LibJS/Lexer.cpp index c9eeebd3a2..74af67b9ea 100644 --- a/Libraries/LibJS/Lexer.cpp +++ b/Libraries/LibJS/Lexer.cpp @@ -451,8 +451,10 @@ Token Lexer::next() consume(); consume(); } - - token_type = TokenType::TemplateLiteralString; + if (is_eof() && !m_template_states.is_empty()) + token_type = TokenType::UnterminatedTemplateLiteral; + else + token_type = TokenType::TemplateLiteralString; } } else if (is_identifier_start()) { // identifier or keyword