Skip to content

Commit c324a75

Browse files
committed
Use RegExpIdentifierName without escape sequences for named captures/backreferences
1 parent dff32fe commit c324a75

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/xregexp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const nativeTokens = {
4949
'class': /\\(?:[0-3][0-7]{0,2}|[4-7][0-7]?|x[\dA-Fa-f]{2}|u(?:[\dA-Fa-f]{4}|{[\dA-Fa-f]+})|c[A-Za-z]|[\s\S])|[\s\S]/
5050
};
5151
// Any backreference or dollar-prefixed character in replacement strings
52-
const replacementToken = /\$(?:{([\w$]+)}|<([\w$]+)>|(\d\d?|[\s\S]))/g;
52+
const replacementToken = /\$(?:\{([\p{ID_Start}$_][\p{ID_Continue}$_\u200C\u200D]*)\}|<([\p{ID_Start}$_][\p{ID_Continue}$_\u200C\u200D]*)>|(\d\d?|[\s\S]))/gu;
5353
// Check for correct `exec` handling of nonparticipating capturing groups
5454
const correctExecNpcg = nativ.exec.call(/()??/, '')[1] === undefined;
5555
// Check for ES6 `flags` prop support
@@ -1792,7 +1792,7 @@ XRegExp.addToken(
17921792
* and $ only. Also allows numbered backreferences as `\k<n>`.
17931793
*/
17941794
XRegExp.addToken(
1795-
/\\k<([\w$]+)>/,
1795+
/\\k<([\p{ID_Start}$_][\p{ID_Continue}$_\u200C\u200D]*)>/u,
17961796
function(match) {
17971797
// Groups with the same name is an error, else would need `lastIndexOf`
17981798
const index = isNaN(match[1]) ? (this.captureNames.indexOf(match[1]) + 1) : +match[1];
@@ -1844,7 +1844,7 @@ XRegExp.addToken(
18441844
* Python-style named capture as octals.
18451845
*/
18461846
XRegExp.addToken(
1847-
/\(\?P?<([\w$]+)>/,
1847+
/\(\?P?<([\p{ID_Start}$_][\p{ID_Continue}$_\u200C\u200D]*)>/u,
18481848
function(match) {
18491849
// Disallow bare integers as names because named backreferences are added to match arrays
18501850
// and therefore numeric properties may lead to incorrect lookups

0 commit comments

Comments
 (0)