ReviewOS

zig-utils/zig-regex

Nested groups are refused far below the depth other engines accept

#25
Open glennmichael123 opened this 8 days ago ·
8 days ago

Split out of #23, which fixed the crashes on flat patterns. This one is a compatibility gap, not a crash: deep nesting already declines cleanly.

Measured

new RegExp("(".repeat(d) + "a" + ")".repeat(d)) through zig-js test262 --eval (ReleaseFast, zig-regex@3e8654e) against node v24.4.1:

nested groupszig-regex (via zig-js)node
50runsruns
200runsruns
500runsruns
1,000SyntaxError: invalid regular expressionruns
2,000SyntaxError: invalid regular expressionruns
5,000SyntaxError: invalid regular expressionruns
20,000SyntaxError: invalid regular expressionSyntaxError

Non-capturing groups behave the same way with a different threshold — (?: nesting runs at 500 and is refused at 2,000 — and a nested quantifier ((?:…)* repeated) is refused from 200. Nested v-flag classes are fine: […] nested 5,000 deep runs.

No depth crashes at any size tested, so this is about where the ceiling sits, not about stack safety.

Unknown

I did not identify what produces the refusal — there is no explicit nesting or depth limit in the parser, and the message reaching JavaScript is zig-js's generic mapping of a compile failure. Worth finding which error the library actually returns before deciding the fix: a raised limit, or a limit that is explicit and documented with a message that says what was exceeded.

Done

Nesting depths that other engines accept either compile, or are refused with an error that names the limit it hit; whichever is chosen, the threshold is pinned by a test so it cannot drift silently.

Sign in to comment on this issue.