LibRegex: Error out on Eof when parsing nonempty class range elements
Fixes #22507.
This commit is contained in:
parent
ee3d09f225
commit
267040dde7
Notes:
sideshowbarker
2024-07-16 22:58:46 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/267040dde7 Pull-request: https://github.com/SerenityOS/serenity/pull/22518 Issue: https://github.com/SerenityOS/serenity/issues/22507
2 changed files with 18 additions and 0 deletions
|
@ -1175,3 +1175,16 @@ TEST_CASE(inversion_state_in_char_class)
|
|||
EXPECT_EQ(result.capture_group_matches.first()[1].view.to_byte_string(), "}"sv);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(mismatching_brackets)
|
||||
{
|
||||
auto const test_cases = Array {
|
||||
"["sv,
|
||||
"[ -"sv,
|
||||
};
|
||||
|
||||
for (auto const& test_case : test_cases) {
|
||||
Regex<ECMA262> re(test_case);
|
||||
EXPECT_EQ(re.parser_result.error, regex::Error::MismatchingBracket);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1963,6 +1963,11 @@ bool ECMA262Parser::parse_nonempty_class_ranges(Vector<CompareTypeAndValuePair>&
|
|||
return {};
|
||||
}
|
||||
|
||||
if (match(TokenType::Eof)) {
|
||||
set_error(Error::MismatchingBracket);
|
||||
return {};
|
||||
}
|
||||
|
||||
if (match(TokenType::RightBracket) || match(TokenType::HyphenMinus))
|
||||
return {};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue