LibJS: Allow unpaired surrogates in String.prototype.replace

This was resulting in a crash for the WPT test case:

https://wpt.live/xhr/send-data-string-invalid-unicode.any.html
This commit is contained in:
Shannon Booth 2024-11-10 22:50:29 +13:00 committed by Tim Flynn
commit e02ca0480f
Notes: github-actions[bot] 2024-11-10 14:14:55 +00:00
2 changed files with 7 additions and 1 deletions

View file

@ -254,3 +254,9 @@ test("substitution with capture group", () => {
expect("A".replace(/(A)/, "$10")).toBe("A0");
expect("A".replace(/(A)/, "$2")).toBe("$2");
});
test("Replace with unpaired surrogate", () => {
expect("$".replace("$", "\ud83d")).toBe("\ud83d");
expect("$ab".replace("$", "\ud83d")).toBe("\ud83dab");
expect("\ud83d$ab".replace("\ud83d$", "ab")).toBe("abab");
});