1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:27:43 +00:00

LibRegex: Allocate entries for all capture groups in RegexResult

Not just the seen ones.
Fixes #6108.
This commit is contained in:
AnotherTest 2021-04-04 15:59:35 +04:30 committed by Andreas Kling
parent ef8f8f47ac
commit 76f63c2980
2 changed files with 21 additions and 21 deletions

View file

@ -88,3 +88,15 @@ test("Future group backreference, #6039", () => {
expect(result[3]).toBe("a");
expect(result.index).toBe(1);
});
// #6108
test("optionally seen capture group", () => {
let rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/;
let ua = "mozilla/4.0 (serenityos; x86) libweb+libjs (not khtml, nor gecko) libweb";
let res = rmozilla.exec(ua);
expect(res.length).toBe(3);
expect(res[0]).toBe("mozilla");
expect(res[1]).toBe("mozilla");
expect(res[2]).toBeUndefined();
});