mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 12:20:00 +01:00
LibRegex: Ensure nullable quantifiers backtrack when input remains
Makes patterns like `/(a?b??)*/` correctly match the string
This commit is contained in:
parent
40c71ff3c0
commit
61744322ad
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -986,6 +986,15 @@ TEST_CASE(extremely_long_fork_chain)
|
|||
EXPECT_EQ(result.success, true);
|
||||
}
|
||||
|
||||
TEST_CASE(nullable_quantifiers)
|
||||
{
|
||||
// clang-format off
|
||||
Regex<ECMA262> 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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user