mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00: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
Notes:
github-actions[bot]
2025-03-02 14:20:04 +00:00
Author: https://github.com/aplefull Commit: https://github.com/LadybirdBrowser/ladybird/commit/61744322ad8 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3752 Reviewed-by: https://github.com/alimpfard
2 changed files with 13 additions and 0 deletions
|
@ -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…
Add table
Reference in a new issue