diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-07-06 11:09:46 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-07-06 22:33:17 +0100 |
commit | 65003241e40cb51605a0e0fcfb5203356af79b6a (patch) | |
tree | eba8455c786beda4ce7bc0312c270167160c9598 /Userland/Libraries | |
parent | d3a2e492fb5a9a3e079e6ceaca0b9e2a6f05c5a6 (diff) | |
download | serenity-65003241e40cb51605a0e0fcfb5203356af79b6a.zip |
LibRegex: Allow dollar signs in ECMA262 named capture groups
Fixes 1 test262 test.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.replace.js | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibRegex/RegexParser.cpp | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.replace.js b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.replace.js index 16d481c9f8..90e306bccb 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.replace.js +++ b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.replace.js @@ -138,6 +138,9 @@ test("replacement with substitution", () => { expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val1>")).toBe("a"); expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val2>")).toBe("c"); expect("abc".replace(/(?<val1>a)b(?<val2>c)/, "$<val2>b$<val1>")).toBe("cba"); + + expect(/(?<𝒜>b)/u[Symbol.replace]("abc", "d$<𝒜>$`")).toBe("adbac"); + expect(/(?<$𐒤>b)/gu[Symbol.replace]("abc", "$'$<$𐒤>d")).toBe("acbdc"); }); test("replacement with substitution and 'groups' coerced to an object", () => { diff --git a/Userland/Libraries/LibRegex/RegexParser.cpp b/Userland/Libraries/LibRegex/RegexParser.cpp index 1c6a78b072..a3a271036f 100644 --- a/Userland/Libraries/LibRegex/RegexParser.cpp +++ b/Userland/Libraries/LibRegex/RegexParser.cpp @@ -1625,7 +1625,7 @@ StringView ECMA262Parser::read_capture_group_specifier(bool take_starting_angle_ auto start_token = m_parser_state.current_token; size_t offset = 0; - while (match(TokenType::Char)) { + while (match(TokenType::Char) || match(TokenType::Dollar)) { auto c = m_parser_state.current_token.value(); if (c == ">") break; |