diff --git a/Libraries/LibRegex/RegexByteCode.cpp b/Libraries/LibRegex/RegexByteCode.cpp index 7ff0b4a6dfb..5447b4f0edf 100644 --- a/Libraries/LibRegex/RegexByteCode.cpp +++ b/Libraries/LibRegex/RegexByteCode.cpp @@ -1118,6 +1118,10 @@ ALWAYS_INLINE ExecutionResult OpCode_JumpNonEmpty::execute(MatchInput const& inp } } + if (state.string_position < input.view.length()) { + return ExecutionResult::Failed_ExecuteLowPrioForks; + } + return ExecutionResult::Continue; } diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp index a5faf6b2dcb..0a69e5f522b 100644 --- a/Tests/LibRegex/Regex.cpp +++ b/Tests/LibRegex/Regex.cpp @@ -986,6 +986,15 @@ TEST_CASE(extremely_long_fork_chain) EXPECT_EQ(result.success, true); } +TEST_CASE(nullable_quantifiers) +{ + // clang-format off + Regex re("(a?b?""?)*"); // Pattern (a?b??)* has to be concatenated to avoid "??)", which is a trigraph. + // clang-format on + auto result = re.match("ab"sv); + EXPECT_EQ(result.matches.at(0).view, "ab"sv); +} + TEST_CASE(theoretically_infinite_loop) { Array patterns {