Skip to content

Commit 8c9c2ee

Browse files
aplefullalimpfard
authored andcommitted
LibRegex: Track local compares in nested classes
1 parent f547933 commit 8c9c2ee

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Libraries/LibRegex/RegexParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,7 @@ bool ECMA262Parser::parse_nested_class(Vector<regex::CompareTypeAndValuePair>& c
24182418
if (match(TokenType::LeftBracket)) {
24192419
consume();
24202420

2421+
auto initial_compares_size = compares.size();
24212422
compares.append(CompareTypeAndValuePair { CharacterCompareType::Or, 0 });
24222423

24232424
if (match(TokenType::Circumflex)) {
@@ -2429,12 +2430,13 @@ bool ECMA262Parser::parse_nested_class(Vector<regex::CompareTypeAndValuePair>& c
24292430
// ClassContents :: [empty]
24302431
if (match(TokenType::RightBracket)) {
24312432
consume();
2433+
auto added_compares = compares.size() - initial_compares_size;
24322434
// Should only have at most an 'Inverse' (after an 'Or')
24332435
if (m_parser_state.regex_options.has_flag_set(regex::AllFlags::UnicodeSets)) {
24342436
// In unicode sets mode, we can have an additional 'And'/'Or' before the 'Inverse'.
2435-
VERIFY(compares.size() <= 3);
2437+
VERIFY(added_compares <= 3);
24362438
} else {
2437-
VERIFY(compares.size() <= 2);
2439+
VERIFY(added_compares <= 2);
24382440
}
24392441
compares.append(CompareTypeAndValuePair { CharacterCompareType::EndAndOr, 0 });
24402442
return true;

Tests/LibRegex/TestRegex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ TEST_CASE(ECMA262_unicode_sets_match)
891891
{ "[\\w&&\\d]"sv, "a"sv, false },
892892
{ "[\\w&&\\d]"sv, "4"sv, true },
893893
{ "([^\\:]+?)"sv, "a"sv, true },
894+
{ "[[a][]]"sv, "a"sv, true }, // ladybird#6647
894895
};
895896

896897
for (auto& test : tests) {

0 commit comments

Comments
 (0)