LibRegex: Correctly advance string positions in Compare::compare_string

Fixes a bug where backreferences could cause desync between the
code point index and regular index, making comparison off-by-N.
This commit is contained in:
Ali Mohammad Pur 2021-09-01 03:09:10 +04:30 committed by Andreas Kling
parent dd82c2e9b4
commit 9b2f0613ef
Notes: sideshowbarker 2024-07-18 04:58:35 +09:00

View file

@ -102,6 +102,12 @@ static void advance_string_position(MatchState& state, RegexStringView const& vi
}
}
static void advance_string_position(MatchState& state, RegexStringView const&, RegexStringView const& advance_by)
{
state.string_position += advance_by.length();
state.string_position_in_code_units += advance_by.length_in_code_units();
}
static void reverse_string_position(MatchState& state, RegexStringView const& view, size_t amount)
{
VERIFY(state.string_position >= amount);
@ -606,7 +612,7 @@ ALWAYS_INLINE bool OpCode_Compare::compare_string(MatchInput const& input, Match
equals = subject.equals(str);
if (equals)
state.string_position += str.length();
advance_string_position(state, input.view, str);
return equals;
}