mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:07:34 +00:00
LibRegex: Implement an ECMA262 Regex quirk with negative lookarounds
This implements the quirk defined by "Note 3" in section "Canonicalize" (https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-ch). Crosses off another quirk from #6042.
This commit is contained in:
parent
bfe8f312f3
commit
c11be92e23
4 changed files with 54 additions and 16 deletions
|
@ -486,7 +486,14 @@ Optional<bool> Matcher<Parser>::execute(MatchInput const& input, MatchState& sta
|
|||
return true;
|
||||
case ExecutionResult::Failed:
|
||||
if (!states_to_try_next.is_empty()) {
|
||||
state = states_to_try_next.take_last();
|
||||
auto next_state = states_to_try_next.take_last();
|
||||
// Note: ECMA262 quirk: Note 3, https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-ch
|
||||
// capture groups defined in lookarounds "leak" outside the regex,
|
||||
// but their contents are empty if the lookaround fails.
|
||||
// This is done by manually clearing the groups where needed, and leaking their contents here.
|
||||
if constexpr (IsSame<Parser, ECMA262>)
|
||||
swap(next_state.capture_group_matches, state.capture_group_matches);
|
||||
state = move(next_state);
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
|
@ -496,7 +503,11 @@ Optional<bool> Matcher<Parser>::execute(MatchInput const& input, MatchState& sta
|
|||
return {};
|
||||
return false;
|
||||
}
|
||||
state = states_to_try_next.take_last();
|
||||
auto next_state = states_to_try_next.take_last();
|
||||
// See note above about an ECMA262 quirk.
|
||||
if constexpr (IsSame<Parser, ECMA262>)
|
||||
swap(next_state.capture_group_matches, state.capture_group_matches);
|
||||
state = move(next_state);
|
||||
++recursion_level;
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue