Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/com/google/javascript/jscomp/parsing/parser/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,18 @@ private Token scanIdentifierOrKeyword(int beginToken, char ch) {
hexDigits = value.substring(escapeStart + 3, escapeEnd);
escapeEnd++;
}
// Identifiers are carried around the compiler as sequences of char (UTF-16 code units), so a
// code point that does not fit in a single char cannot be represented here. The value used
// to be cast straight to char, which silently kept only the low 16 bits: a braced escape for
// U+10041 was accepted as the identifier "A", and even code points above the U+10FFFF
// maximum (e.g. U+110041) slipped through the same way. Reject anything outside the BMP
// rather than aliasing it to a different character.
// TODO(mattloring): Allow code points >= 0xFFFF (greater than the size of a char).
char ch = (char) Integer.parseInt(hexDigits, 0x10);
int codePoint = Integer.parseInt(hexDigits, 0x10);
if (codePoint > 0xFFFF) {
return null;
}
char ch = (char) codePoint;
if (!Identifiers.isIdentifierPart(ch)) {
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions test/com/google/javascript/jscomp/parsing/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5221,6 +5221,11 @@ public void testInvalidUnicodePointEscapeInIdentifiers() {
// Legal unicode but invalid in identifier
parseError("Js\\u{99}ompiler", "Invalid escape sequence");
parseError("Js\\u{10000}ompiler", "Invalid escape sequence");
// Code points outside the BMP must not be truncated to their low 16 bits. U+10041 shares its
// low bits with U+0041 ('A') and U+110041 is above the U+10FFFF maximum; both used to be
// silently accepted.
parseError("Js\\u{10041}ompiler", "Invalid escape sequence");
parseError("Js\\u{110041}ompiler", "Invalid escape sequence");
}

@Test
Expand Down
Loading