mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Move regex logic to main Lexer if statement
This prevents a regex such as /=/ from lexing into TokenType::SlashEquals, preventing the regex logic from working.
This commit is contained in:
parent
cc7462daeb
commit
bc1c556755
Notes:
sideshowbarker
2024-07-19 05:45:46 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/bc1c5567555 Pull-request: https://github.com/SerenityOS/serenity/pull/2527
1 changed files with 23 additions and 22 deletions
|
@ -418,6 +418,29 @@ Token Lexer::next()
|
|||
consume();
|
||||
token_type = TokenType::StringLiteral;
|
||||
}
|
||||
} else if (m_current_char == '/' && !slash_means_division()) {
|
||||
consume();
|
||||
token_type = TokenType::RegexLiteral;
|
||||
|
||||
while (!is_eof()) {
|
||||
if (m_current_char == '[') {
|
||||
m_regex_is_in_character_class = true;
|
||||
} else if (m_current_char == ']') {
|
||||
m_regex_is_in_character_class = false;
|
||||
} else if (!m_regex_is_in_character_class && m_current_char == '/') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (match('\\', '/') || match('\\', '[') || match('\\', '\\') || (m_regex_is_in_character_class && match('\\', ']')))
|
||||
consume();
|
||||
consume();
|
||||
}
|
||||
|
||||
if (is_eof()) {
|
||||
token_type = TokenType::UnterminatedRegexLiteral;
|
||||
} else {
|
||||
consume();
|
||||
}
|
||||
} else if (m_current_char == EOF) {
|
||||
token_type = TokenType::Eof;
|
||||
} else {
|
||||
|
@ -473,28 +496,6 @@ Token Lexer::next()
|
|||
if (!found_four_char_token && !found_three_char_token && !found_two_char_token && !found_one_char_token) {
|
||||
consume();
|
||||
token_type = TokenType::Invalid;
|
||||
} else if (token_type == TokenType::Slash && !slash_means_division()) {
|
||||
token_type = TokenType::RegexLiteral;
|
||||
|
||||
while (!is_eof()) {
|
||||
if (m_current_char == '[') {
|
||||
m_regex_is_in_character_class = true;
|
||||
} else if (m_current_char == ']') {
|
||||
m_regex_is_in_character_class = false;
|
||||
} else if (!m_regex_is_in_character_class && m_current_char == '/') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (match('\\', '/') || match('\\', '[') || match('\\', '\\') || (m_regex_is_in_character_class && match('\\', ']')))
|
||||
consume();
|
||||
consume();
|
||||
}
|
||||
|
||||
if (is_eof()) {
|
||||
token_type = TokenType::UnterminatedRegexLiteral;
|
||||
} else {
|
||||
consume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue