1
0
Fork 0
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:
aplefull 2025-05-31 19:49:43 +02:00 committed by Ali Mohammad Pur
parent 2380fb0ca1
commit 486602e796
Notes: github-actions[bot] 2025-06-02 13:53:33 +00:00
2 changed files with 15 additions and 2 deletions

View file

@ -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::Failed_ExecuteLowPrioForks;
}
return ExecutionResult::Continue; return ExecutionResult::Continue;
} }

View file

@ -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); 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);
}
}