JS: Extract surrogate pairs as one constant node

This commit is contained in:
Asger F
2019-10-24 12:23:30 +01:00
parent 6e1c995f2f
commit 68d23bcf8c
2 changed files with 9 additions and 2 deletions

View File

@@ -489,6 +489,11 @@ public class RegExpParser {
if (this.match("b")) return this.finishTerm(new ControlEscape(loc, "\b", 8, "\\b"));
return this.finishTerm(this.parseAtomEscape(loc, true));
}
return this.finishTerm(new Constant(loc, String.valueOf(c)));
String value = String.valueOf(c);
// Extract a surrogate pair as a single constant.
if (Character.isHighSurrogate(c) && Character.isLowSurrogate(peekChar(true))) {
value += this.nextChar();
}
return this.finishTerm(new Constant(loc, value));
}
}

View File

@@ -8,4 +8,6 @@
/[aaa]/;
/[\x0a\x0a]/;
/[\u000a\n]/;
/[\u{ff}]/;
/[\u{ff}]/;
/[\u{12340}-\u{12345}]/u; // OK
new RegExp("[\u{12340}-\u{12345}]", "u"); // OK