From 0f0ac37b56884f473637ad53defd7e4b6d8bc430 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 9 Jul 2021 09:33:02 -0400 Subject: [PATCH] LibRegex: Break from execution loop when the sticky flag is set If the sticky flag is set, the regex execution loop should break immediately even if the execution was a failure. The specification for several RegExp.prototype methods (e.g. exec and @@split) rely on this behavior. --- Userland/Libraries/LibRegex/RegexMatcher.cpp | 2 +- Userland/Libraries/LibRegex/RegexMatcher.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibRegex/RegexMatcher.cpp b/Userland/Libraries/LibRegex/RegexMatcher.cpp index a7ade1f533..e9eb2ddcbf 100644 --- a/Userland/Libraries/LibRegex/RegexMatcher.cpp +++ b/Userland/Libraries/LibRegex/RegexMatcher.cpp @@ -237,7 +237,7 @@ RegexResult Matcher::match(const Vector views, Optional break; } - if (!continue_search && !input.regex_options.has_flag_set(AllFlags::Internal_Stateful)) + if (!continue_search) break; } diff --git a/Userland/Libraries/LibRegex/RegexMatcher.h b/Userland/Libraries/LibRegex/RegexMatcher.h index 5e3c63cf2c..57dad88535 100644 --- a/Userland/Libraries/LibRegex/RegexMatcher.h +++ b/Userland/Libraries/LibRegex/RegexMatcher.h @@ -149,6 +149,7 @@ public: options.reset_flag(AllFlags::MatchNotEndOfLine); options.reset_flag(AllFlags::MatchNotBeginOfLine); } + options.reset_flag(AllFlags::Internal_Stateful); options |= AllFlags::Global; return matcher->match(view, options); @@ -164,6 +165,7 @@ public: options.reset_flag(AllFlags::MatchNotEndOfLine); options.reset_flag(AllFlags::MatchNotBeginOfLine); } + options.reset_flag(AllFlags::Internal_Stateful); options |= AllFlags::Global; return matcher->match(views, options);