LibRegex: Account for extra explicit And/Or in class parser assertion

Fixes #23691.
This commit is contained in:
Ali Mohammad Pur 2024-03-24 00:22:43 +01:00 committed by Andreas Kling
parent 259a84ddac
commit 27a38932da
Notes: sideshowbarker 2024-07-17 04:01:41 +09:00
2 changed files with 7 additions and 1 deletions

View file

@ -800,6 +800,7 @@ TEST_CASE(ECMA262_unicode_sets_parser_error)
constexpr _test tests[] { constexpr _test tests[] {
{ "[[]"sv, regex::Error::InvalidPattern }, { "[[]"sv, regex::Error::InvalidPattern },
{ "[[x[]]]"sv, regex::Error::NoError }, // #23691, should not crash on empty charclass within AndOr.
}; };
for (auto test : tests) { for (auto test : tests) {

View file

@ -2386,7 +2386,12 @@ bool ECMA262Parser::parse_nested_class(Vector<regex::CompareTypeAndValuePair>& c
if (match(TokenType::RightBracket)) { if (match(TokenType::RightBracket)) {
consume(); consume();
// Should only have at most an 'Inverse' (after an 'Or') // Should only have at most an 'Inverse' (after an 'Or')
VERIFY(compares.size() <= 2); if (m_parser_state.regex_options.has_flag_set(regex::AllFlags::UnicodeSets)) {
// In unicode sets mode, we can have an additional 'And'/'Or' before the 'Inverse'.
VERIFY(compares.size() <= 3);
} else {
VERIFY(compares.size() <= 2);
}
compares.append(CompareTypeAndValuePair { CharacterCompareType::EndAndOr, 0 }); compares.append(CompareTypeAndValuePair { CharacterCompareType::EndAndOr, 0 });
return true; return true;
} }