mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
LibRegex: Fix handling of + quantifier with zero-width matches
Small change that allows quantifiers using Fork* forms (e.g., +) to succeed after one match, even if that match has zero width.
This commit is contained in:
parent
2380fb0ca1
commit
486602e796
Notes:
github-actions[bot]
2025-06-02 13:53:33 +00:00
Author: https://github.com/aplefull
Commit: 486602e796
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4949
Reviewed-by: https://github.com/alimpfard ✅
Reviewed-by: https://github.com/trflynn89
2 changed files with 15 additions and 2 deletions
|
@ -1121,9 +1121,8 @@ ALWAYS_INLINE ExecutionResult OpCode_JumpNonEmpty::execute(MatchInput const& inp
|
|||
}
|
||||
}
|
||||
|
||||
if (state.string_position < input.view.length()) {
|
||||
if (form() == OpCodeId::Jump && state.string_position < input.view.length())
|
||||
return ExecutionResult::Failed_ExecuteLowPrioForks;
|
||||
}
|
||||
|
||||
return ExecutionResult::Continue;
|
||||
}
|
||||
|
|
|
@ -1298,3 +1298,17 @@ TEST_CASE(optimizer_repeat_offset)
|
|||
Regex<ECMA262> re("\\/?\\??#?([\\/?#]|[\\uD800-\\uDBFF]|%[c-f][0-9a-f](%[89ab][0-9a-f]){0,2}(%[89ab]?)?|%[0-9a-f]?)$"sv);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(zero_width_backreference)
|
||||
{
|
||||
{
|
||||
// Ensure that a zero-width backreference will match correctly.
|
||||
Regex<ECMA262> re("(a*)b\\1+", ECMAScriptFlags::Global);
|
||||
auto result = re.match("baaac"sv);
|
||||
|
||||
EXPECT_EQ(result.success, true);
|
||||
EXPECT_EQ(result.matches.size(), 1u);
|
||||
EXPECT_EQ(result.matches.first().view.to_byte_string(), "b"sv);
|
||||
EXPECT_EQ(result.capture_group_matches.first()[0].view.to_byte_string(), ""sv);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue