mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibRegex: Allow ClearCaptureGroup to create new groups
Instead of leaking all capture groups and selectively clearing some, simply avoid leaking things and only "define" the ones that need to exist. This *actually* implements the capture groups ECMA262 quirk. Also adds the test removed in the previous commit (to avoid messing up test runs across bisects).
This commit is contained in:
parent
704e0654b3
commit
97dde09170
Notes:
sideshowbarker
2024-07-17 20:29:32 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/97dde091702 Pull-request: https://github.com/SerenityOS/serenity/pull/12057
2 changed files with 6 additions and 2 deletions
|
@ -682,6 +682,7 @@ TEST_CASE(ECMA262_match)
|
|||
{ "[\\0]"sv, "\0"sv, true, combine_flags(ECMAScriptFlags::Unicode, ECMAScriptFlags::BrowserExtended) },
|
||||
{ "[\\01]"sv, "\1"sv, true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "(\0|a)"sv, "a"sv, true }, // #9686, Should allow null bytes in pattern
|
||||
{ "(.*?)a(?!(a+)b\\2c)\\2(.*)"sv, "baaabaac"sv, true }, // #6042, Groups inside lookarounds may be referenced outside, but their contents appear empty if the pattern in the lookaround fails.
|
||||
{ "a|$"sv, "x"sv, true, (ECMAScriptFlags)regex::AllFlags::Global }, // #11940, Global (not the 'g' flag) regexps should attempt to match the zero-length end of the string too.
|
||||
};
|
||||
// clang-format on
|
||||
|
|
|
@ -329,8 +329,11 @@ ALWAYS_INLINE ExecutionResult OpCode_ClearCaptureGroup::execute(MatchInput const
|
|||
{
|
||||
if (input.match_index < state.capture_group_matches.size()) {
|
||||
auto& group = state.capture_group_matches[input.match_index];
|
||||
if (id() < group.size())
|
||||
group[id()].reset();
|
||||
auto group_id = id();
|
||||
if (group_id >= group.size())
|
||||
group.resize(group_id + 1);
|
||||
|
||||
group[group_id].reset();
|
||||
}
|
||||
return ExecutionResult::Continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue