mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibRegex: Make infinite repetitions short-circuit on empty matches
This makes (addmittedly weird) patterns like `(a*)*` work correctly without going into an infinite fork loop.
This commit is contained in:
parent
f8570bd773
commit
abbe9da255
4 changed files with 131 additions and 69 deletions
|
@ -852,6 +852,21 @@ TEST_CASE(extremely_long_fork_chain)
|
|||
EXPECT_EQ(result.success, true);
|
||||
}
|
||||
|
||||
TEST_CASE(theoretically_infinite_loop)
|
||||
{
|
||||
Array patterns {
|
||||
"(a*)*"sv, // Infinitely matching empty substrings, the outer loop should short-circuit.
|
||||
"(a*?)*"sv, // Infinitely matching empty substrings, the outer loop should short-circuit.
|
||||
"(a*)*?"sv, // Should match exactly nothing.
|
||||
"(?:)*?"sv, // Should not generate an infinite fork loop.
|
||||
};
|
||||
for (auto& pattern : patterns) {
|
||||
Regex<ECMA262> re(pattern);
|
||||
auto result = re.match("");
|
||||
EXPECT_EQ(result.success, true);
|
||||
}
|
||||
}
|
||||
|
||||
static auto g_lots_of_a_s = String::repeated('a', 10'000'000);
|
||||
|
||||
BENCHMARK_CASE(fork_performance)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue