| 1 |
// Copyright 2017 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Exotic named group names in non-Unicode RegExps |
| 6 |
esid: prod-GroupSpecifier |
| 7 |
features: [regexp-named-groups] |
| 8 |
includes: [compareArray.js] |
| 9 |
---*/ |
| 10 |
|
| 11 |
assert.sameValue("a", /(?<π>a)/.exec("bab").groups.π); |
| 12 |
assert.throws(SyntaxError, () => eval('/(?<\\u{03C0}>a)/'), "\\u{} escapes allowed only in Unicode mode"); |
| 13 |
assert.sameValue("a", /(?<π>a)/.exec("bab").groups.\u03C0); |
| 14 |
assert.sameValue("a", /(?<$>a)/.exec("bab").groups.$); |
| 15 |
assert.sameValue("a", /(?<_>a)/.exec("bab").groups._); |
| 16 |
assert.throws(SyntaxError, () => eval('/(?<$𐒤>a)/'), "Individual surrogates not in ID_Continue"); |
| 17 |
assert.sameValue("a", /(?<_\u200C>a)/.exec("bab").groups._\u200C); |
| 18 |
assert.sameValue("a", /(?<_\u200D>a)/.exec("bab").groups._\u200D); |
| 19 |
assert.sameValue("a", /(?<ಠ_ಠ>a)/.exec("bab").groups.ಠ_ಠ); |
| 20 |
assert.throws(SyntaxError, () => eval('/(?<❤>a)/')); |
| 21 |
assert.throws(SyntaxError, () => eval('/(?<𐒤>a)/'), "Individual surrogate not in ID_Start."); |
| 22 |
|
| 23 |
// Unicode escapes in capture names. |
| 24 |
assert.throws(SyntaxError, () => eval("/(?<a\\uD801\uDCA4>.)/")); |
| 25 |
assert.throws(SyntaxError, () => eval("/(?<a\\uD801>.)/")); |
| 26 |
assert.throws(SyntaxError, () => eval("/(?<a\\uDCA4>.)/")); |
| 27 |
assert(/(?<\u0041>.)/.test("a")); |
| 28 |
assert.throws(SyntaxError, () => eval("/(?<a\\u{104A4}>.)/")); |
| 29 |
assert.throws(SyntaxError, () => eval("/(?<a\\u{10FFFF}>.)/")); |
| 30 |
assert.throws(SyntaxError, () => eval("/(?<a\uD801>.)/"), "Lea"); |
| 31 |
assert.throws(SyntaxError, () => eval("/(?<a\uDCA4>.)/"), "Trai"); |
| 32 |
assert(RegExp("(?<\u{0041}>.)").test("a"), "Non-surrogate"); |
| 33 |
|
| 34 |
// Bracketed escapes are not allowed; |
| 35 |
// 4-char escapes must be the proper ID_Start/ID_Continue |
| 36 |
assert.throws(SyntaxError, () => eval("/(?<a\\uD801>.)/"), "Lead"); |
| 37 |
assert.throws(SyntaxError, () => eval("/(?<a\\uDCA4>.)/"), "Trail"); |
| 38 |
assert.throws(SyntaxError, () => eval("/(?<\\u{0041}>.)/"), "Non-surrogate"); |
| 39 |
assert.throws(SyntaxError, () => eval("/(?<a\\u{104A4}>.)/"), "Surrogate, ID_Continue"); |
| 40 |
assert(RegExp("(?<\\u0041>.)").test("a"), "Non-surrogate"); |
| 41 |
|
| 42 |
// Backslash is not allowed as ID_Start and ID_Continue |
| 43 |
assert.throws(SyntaxError, () => eval("/(?<\\>.)/"), "'\' misclassified as ID_Start"); |
| 44 |
assert.throws(SyntaxError, () => eval("/(?<a\\>.)/"), "'\' misclassified as ID_Continue"); |