ladybird/Tests/LibJS/Runtime/regexp-bounded-lazy-zero-width-quantifier.js
aplefull 201c129973 LibRegex: Emit progress check for optional iterations in bounded quants
Optional iterations in bounded quantifiers like {2,3} only emitted a
zero-width progress check when the outer min was 0. It made patterns
like /(?:a*?){2,3}/ match empty string even on non-empty input.

RepeatMatcher step 2.b states that the check must fire
whenever min reaches 0, which corresponds to every optional iteration.
2026-05-26 10:00:22 +02:00

18 lines
726 B
JavaScript

test("bounded lazy zero-width group requires progress at optional boundary", () => {
expect(/(?:a*?){2,3}/.exec("a")[0]).toBe("a");
expect(/(?:a*?){2,3}/.exec("aa")[0]).toBe("a");
expect(/(?:a*?){2,3}/.exec("aaa")[0]).toBe("a");
expect(/(?:a*?){2,3}/.exec("")[0]).toBe("");
expect(/(?:a*?){2,3}/.exec("b")[0]).toBe("");
});
test("bounded lazy zero-width group with min=1", () => {
expect(/(?:a*?){1,2}/.exec("a")[0]).toBe("a");
expect(/(?:a*?){1,2}/.exec("")[0]).toBe("");
});
test("bounded lazy zero-width group with unbounded max", () => {
expect(/(?:a*?){2,}/.exec("a")[0]).toBe("a");
expect(/(?:a*?){2,}/.exec("aa")[0]).toBe("aa");
expect(/(?:a*?){2,}/.exec("")[0]).toBe("");
});