mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibRegex: Do not continue searching input when the sticky bit is set
This partially reverts commit a962ee020a
.
When the sticky bit is set, the global bit should basically be ignored
except by external callers who want their own special behavior. For
example, RegExp.prototype [ @@match ] will use the global flag to
accumulate consecutive matches. But on the first failure, the regex
loop should break.
This commit is contained in:
parent
222e580fa8
commit
27d3de1f17
Notes:
sideshowbarker
2024-07-17 19:46:39 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/27d3de1f170 Pull-request: https://github.com/SerenityOS/serenity/pull/12295
2 changed files with 15 additions and 1 deletions
|
@ -70,3 +70,11 @@ test("escaped code points", () => {
|
|||
expect(string.match(re).groups.𝓑𝓻𝓸𝔀𝓷).toBe("brown");
|
||||
expect(string.match(re).groups.𝓑𝓻𝓸𝔀𝓷).toBe("brown");
|
||||
});
|
||||
|
||||
test("sticky and global flag set", () => {
|
||||
const string = "aaba";
|
||||
expect(string.match(/a/)).toEqual(["a"]);
|
||||
expect(string.match(/a/y)).toEqual(["a"]);
|
||||
expect(string.match(/a/g)).toEqual(["a", "a", "a"]);
|
||||
expect(string.match(/a/gy)).toEqual(["a", "a"]);
|
||||
});
|
||||
|
|
|
@ -180,6 +180,8 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
|
|||
#endif
|
||||
|
||||
bool continue_search = input.regex_options.has_flag_set(AllFlags::Global) || input.regex_options.has_flag_set(AllFlags::Multiline);
|
||||
if (input.regex_options.has_flag_set(AllFlags::Sticky))
|
||||
continue_search = false;
|
||||
|
||||
auto single_match_only = input.regex_options.has_flag_set(AllFlags::SingleMatch);
|
||||
|
||||
|
@ -280,7 +282,11 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
|
|||
break;
|
||||
continue;
|
||||
}
|
||||
if (state.string_position < view_length && !input.regex_options.has_flag_set(AllFlags::Internal_Stateful)) {
|
||||
if (input.regex_options.has_flag_set(AllFlags::Internal_Stateful)) {
|
||||
append_match(input, state, view_index);
|
||||
break;
|
||||
}
|
||||
if (state.string_position < view_length) {
|
||||
return { false, 0, {}, {}, {}, operations };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue