1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:37:45 +00:00

LibRegex: Allow references to capture groups that aren't parsed yet

This only applies to the ECMA262 parser.
This behaviour is an ECMA262-specific quirk, such references always
generate zero-length matches (even on subsequent passes).
Also adds a test in LibJS's test suite.

Fixes #6039.
This commit is contained in:
AnotherTest 2021-04-01 18:30:47 +04:30 committed by Andreas Kling
parent 804ab79995
commit 6bbb26fdaf
6 changed files with 80 additions and 6 deletions

View file

@ -66,3 +66,15 @@ test("not matching", () => {
expect(res).toBe(null);
});
// Backreference to a group not yet parsed: #6039
test("Future group backreference, #6039", () => {
let re = /(\3)(\1)(a)/;
let result = re.exec("cat");
expect(result.length).toBe(4);
expect(result[0]).toBe("a");
expect(result[1]).toBe("");
expect(result[2]).toBe("");
expect(result[3]).toBe("a");
expect(result.index).toBe(1);
});