Commit f3b848fe authored by jgruber's avatar jgruber Committed by Commit bot

[regexp] Updates for unicode escapes in capture names

Update docs and tests for recent changes in the spec for unicode escapes
in capture group names.

https://github.com/tc39/proposal-regexp-named-groups/issues/23

BUG=v8:5437

Review-Url: https://codereview.chromium.org/2788423003
Cr-Commit-Position: refs/heads/master@{#44474}
parent 2e889e4d
......@@ -700,10 +700,6 @@ void RegExpParser::ScanForCaptures() {
if (current() != '<') break;
if (FLAG_harmony_regexp_lookbehind) {
// TODO(jgruber): To be more future-proof we could test for
// IdentifierStart here once it becomes clear whether group names
// allow unicode escapes.
// https://github.com/tc39/proposal-regexp-named-groups/issues/23
Advance();
if (current() == '=' || current() == '!') break;
}
......@@ -783,8 +779,6 @@ const ZoneVector<uc16>* RegExpParser::ParseCaptureGroupName() {
// Convert unicode escapes.
if (c == '\\' && current() == 'u') {
// TODO(jgruber): Reconsider this once the spec has settled.
// https://github.com/tc39/proposal-regexp-named-groups/issues/23
Advance(scan_mode);
if (!ParseUnicodeEscape(&c)) {
ReportError(CStrVector("Invalid Unicode escape sequence"));
......
......@@ -187,6 +187,31 @@ assertThrows("/\\1(?<=a)./u", SyntaxError);
assertThrows("/\\1(?<!a)./u", SyntaxError);
assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd"));
// Unicode escapes in capture names.
assertTrue(/(?<a\uD801\uDCA4>.)/u.test("a")); // \u Lead \u Trail
assertThrows("/(?<a\\uD801>.)/u", SyntaxError); // \u Lead
assertThrows("/(?<a\\uDCA4>.)/u", SyntaxError); // \u Trail
assertTrue(/(?<\u0041>.)/u.test("a")); // \u NonSurrogate
assertTrue(/(?<\u{0041}>.)/u.test("a")); // \u{ Non-surrogate }
assertTrue(/(?<a\u{104A4}>.)/u.test("a")); // \u{ Surrogate, ID_Continue }
assertThrows("/(?<a\\u{110000}>.)/u", SyntaxError); // \u{ Out-of-bounds }
assertThrows("/(?<a\uD801>.)/u", SyntaxError); // Lead
assertThrows("/(?<a\uDCA4>.)/u", SyntaxError); // Trail
assertTrue(RegExp("(?<\u{0041}>.)", "u").test("a")); // Non-surrogate
assertTrue(RegExp("(?<a\u{104A4}>.)", "u").test("a")); // Surrogate,ID_Continue
assertThrows("/(?<a\\uD801\uDCA4>.)/", SyntaxError);
assertThrows("/(?<a\\uD801>.)/", SyntaxError);
assertThrows("/(?<a\\uDCA4>.)/", SyntaxError);
assertTrue(/(?<\u0041>.)/.test("a"));
assertThrows("/(?<\\u{0041}>.)/", SyntaxError);
assertThrows("/(?<a\\u{104A4}>.)/", SyntaxError);
assertThrows("/(?<a\\u{10FFFF}>.)/", SyntaxError);
assertThrows("/(?<a\uD801>.)/", SyntaxError); // Lead
assertThrows("/(?<a\uDCA4>.)/", SyntaxError); // Trail
assertTrue(RegExp("(?<\u{0041}>.)").test("a")); // Non-surrogate
assertTrue(RegExp("(?<a\u{104A4}>.)").test("a")); // Surrogate, ID_Continue
// @@replace with a callable replacement argument (no named captures).
{
let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment