mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:07:34 +00:00
LibJS: Disallow whitespace or comments between regex literal and flags
If we consumed whitespace and/or comments after a RegexLiteral token, the following token must not be RegexFlags - no whitespace or comments are allowed between the closing / and the flag characters. Fixes #8201.
This commit is contained in:
parent
ab7023dbe5
commit
714a96619f
1 changed files with 2 additions and 1 deletions
|
@ -390,12 +390,13 @@ Token Lexer::next()
|
||||||
size_t value_start_line_number = m_line_number;
|
size_t value_start_line_number = m_line_number;
|
||||||
size_t value_start_column_number = m_line_column;
|
size_t value_start_column_number = m_line_column;
|
||||||
auto token_type = TokenType::Invalid;
|
auto token_type = TokenType::Invalid;
|
||||||
|
auto did_consume_whitespace_or_comments = trivia_start != value_start;
|
||||||
// This is being used to communicate info about invalid tokens to the parser, which then
|
// This is being used to communicate info about invalid tokens to the parser, which then
|
||||||
// can turn that into more specific error messages - instead of us having to make up a
|
// can turn that into more specific error messages - instead of us having to make up a
|
||||||
// bunch of Invalid* tokens (bad numeric literals, unterminated comments etc.)
|
// bunch of Invalid* tokens (bad numeric literals, unterminated comments etc.)
|
||||||
String token_message;
|
String token_message;
|
||||||
|
|
||||||
if (m_current_token.type() == TokenType::RegexLiteral && !is_eof() && is_ascii_alpha(m_current_char)) {
|
if (m_current_token.type() == TokenType::RegexLiteral && !is_eof() && is_ascii_alpha(m_current_char) && !did_consume_whitespace_or_comments) {
|
||||||
token_type = TokenType::RegexFlags;
|
token_type = TokenType::RegexFlags;
|
||||||
while (!is_eof() && is_ascii_alpha(m_current_char))
|
while (!is_eof() && is_ascii_alpha(m_current_char))
|
||||||
consume();
|
consume();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue