mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:48:13 +00:00
LibRegex: Prevent patterns from matching the empty string twice
Previously, if a pattern matched the empty string (e.g. ".*"), it would match the string twice instead of once. Among other issues, this caused a Regex replacement to duplicate its expected output, since it would replace "both" empty matches.
This commit is contained in:
parent
5bf2cce839
commit
87a961534f
2 changed files with 17 additions and 0 deletions
|
@ -222,6 +222,11 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
|
|||
// Nothing was *actually* matched, so append an empty match.
|
||||
append_match(input, state, view_index);
|
||||
++match_count;
|
||||
|
||||
// This prevents a regex pattern like ".*" from matching the empty string
|
||||
// multiple times, once in this block and once in the following for loop.
|
||||
if (view_index == 0 && view_length == 0)
|
||||
++view_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue