1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:47:44 +00:00

LibJS: Convert matched regex result to string in Symbol.replace

This would crash on an undefined match (no match), since the matched
result was assumed to be a string (such as on discord.com). The spec
suggests converting it to a string as well:
https://tc39.es/ecma262/#sec-regexp.prototype-@@replace (14#c)
This commit is contained in:
Idan Horowitz 2021-04-17 15:46:19 +03:00 committed by Linus Groh
parent 358697a32f
commit 6cd318d784
2 changed files with 14 additions and 3 deletions

View file

@ -148,3 +148,10 @@ test("empty character class semantics", () => {
expect(res.length).toBe(1);
expect(res[0]).toBe("x");
});
// #6409
test("undefined match result", () => {
const r = /foo/;
r.exec = () => ({});
expect(r[Symbol.replace]()).toBe("undefined");
});