Skip to content

Commit 1d98ea1

Browse files
committed
Added some comments to describe handling of undefined backreferences with non-octal chars (ex. \9).
Signed-off-by: Grant Skinner <[email protected]>
1 parent 164e336 commit 1d98ea1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

js/RegExLexer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,14 @@ SOFTWARE.
234234
};
235235

236236
p.parseEsc = function(str, token, charset, capgroups, closeIndex) {
237-
// jsMode tries to read escape chars as a JS string which is less permissive than JS RegExp,
238-
// and doesn't support \c or backreferences
237+
// jsMode tries to read escape chars as a JS string which is less permissive than JS RegExp, and doesn't support \c or backreferences, used for subst
238+
239+
// Note: \8 & \9 are treated differently: IE & Chrome match "8", Safari & FF match "\8", we support the former case since Chrome & IE are dominant
240+
// Note: in Chrome \u & \x will match u & x in a set, but outside it they are decomposed \\x, RegExr does not support this case
239241
var i = token.i, jsMode = token.js, match, o;
240242
var sub = str.substr(i+1), c=sub[0];
241243
if (i+1 == (closeIndex||str.length)) { token.err = "esccharopen"; return; }
242244

243-
// TODO: Note that in Chrome: \u & \x will match u & x in a set, but outside it they are decomposed \\x
244245

245246
if (!jsMode && !charset && (match = sub.match(/^\d\d?/)) && (o = capgroups[parseInt(match[0])-1])) {
246247
// back reference - only if there is a matching capture group

0 commit comments

Comments
 (0)