ladybird/Libraries/LibRegex
Shannon Booth ba59640ab2 LibRegex: Avoid hitting backtrack limit for bounded grouped repetitions
Unrolling a bounded quantifier {min,max} into (max-min) optional Split
chains lets the backtracker explore O(2^n) paths, which quickly
exhausts the backtrack limit for large bounds.

Fix this by compiling the optional tail via a RepeatStart/RepeatCheck
counted loop when the atom is known to be non-zero-width. The loop
is safe to use without a progress check precisely because the atom
cannot match empty.

This required making atom_can_be_zero_width recursive into group bodies:
previously it conservatively returned true for all Group and
NonCapturingGroup atoms, so the non-zero-width guard could never fire
for grouped subexpressions.

The old lowering triggered "Regular expression backtrack limit exceeded"
for patterns like /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/, causing
inputs that should match normally (or return null) to throw instead.

Fixes syntax highlighting of the C++ API on https://blend2d.com
2026-04-11 18:43:48 +02:00
..
Rust LibRegex: Avoid hitting backtrack limit for bounded grouped repetitions 2026-04-11 18:43:48 +02:00
CMakeLists.txt AK: Adopt mimalloc v2 as main allocator 2026-04-08 09:57:53 +02:00
ECMAScriptRegex.cpp LibRegex: Respect V8 astral literal lastIndex behavior 2026-03-27 17:32:19 +01:00
ECMAScriptRegex.h LibRegex: Respect V8 astral literal lastIndex behavior 2026-03-27 17:32:19 +01:00
RustRegex.cpp LibRegex: Use Unicode ID_Start/ID_Continue for named group names 2026-04-08 07:31:54 -04:00
RustRegex.h Meta: Remove ENABLE_RUST build configuration option 2026-04-02 22:59:42 +02:00