mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
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:
parent
dd82c2e9b4
commit
9b2f0613ef
Notes:
sideshowbarker
2024-07-18 04:58:35 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/9b2f0613ef0 Pull-request: https://github.com/SerenityOS/serenity/pull/9710 Issue: https://github.com/SerenityOS/serenity/issues/9707
1 changed files with 7 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue