1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:57:35 +00:00

LibJS: Manually loop over escaped regex pattern instead of ::replace()

This makes it ever-so-slightly faster, but more importantly, it fixes
the bug where a `/\//` regex's `source` property would return `\\/`
("\\\\/") instead of `\/` due to the existing '/' -> '\/' replace()
call.
This commit is contained in:
Ali Mohammad Pur 2023-02-15 17:55:13 +03:30 committed by Linus Groh
parent a8bcb901c0
commit bcfbe0fbf7
2 changed files with 25 additions and 3 deletions

View file

@ -3,6 +3,5 @@ test("basic functionality", () => {
expect(RegExp().source).toBe("(?:)");
expect(/test/.source).toBe("test");
expect(/\n/.source).toBe("\\n");
// FIXME: RegExp parse doesn't parse \/ :(
// expect(/foo\/bar/.source).toBe("foo\\/bar");
expect(/foo\/bar/.source).toBe("foo\\/bar");
});