Skip to content

Commit

Permalink
Invalid Identifier by Unicode escape
Browse files Browse the repository at this point in the history
  • Loading branch information
tuchida authored and gbrail committed Aug 27, 2023
1 parent 86a01e1 commit 90ac409
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
27 changes: 27 additions & 0 deletions src/org/mozilla/javascript/TokenStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,25 @@ private static int stringToKeywordForES(String name, boolean isStrict) {
return id & 0xff;
}

private static boolean isValidIdentifierName(String str) {
int i = 0;
for (int c : str.codePoints().toArray()) {
if (i++ == 0) {
if (c != '$' && c != '_' && !Character.isUnicodeIdentifierStart(c)) {
return false;
}
} else {
if (c != '$'
&& c != '\u200c'
&& c != '\u200d'
&& !Character.isUnicodeIdentifierPart(c)) {
return false;
}
}
}
return true;
}

final String getSourceString() {
return sourceString;
}
Expand Down Expand Up @@ -779,6 +798,14 @@ final int getToken() throws IOException {
// we convert the last character back to unicode
str = convertLastCharToHex(str);
}

if (containsEscape
&& parser.compilerEnv.getLanguageVersion() >= Context.VERSION_ES6
&& !isValidIdentifierName(str)) {
parser.reportError("msg.invalid.escape");
return Token.ERROR;
}

this.string = (String) allStrings.intern(str);
return Token.NAME;
}
Expand Down
43 changes: 23 additions & 20 deletions testsrc/test262.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5067,31 +5067,48 @@ language/global-code 29/41 (70.73%)

language/identifier-resolution 0/13 (0.0%)

language/identifiers 28/188 (14.89%)
language/identifiers 45/188 (23.94%)
other_id_continue.js
other_id_continue-escaped.js
other_id_start.js
other_id_start-escaped.js
part-unicode-10.0.0.js
part-unicode-10.0.0-escaped.js
part-unicode-11.0.0.js
part-unicode-11.0.0-escaped.js
part-unicode-12.0.0.js
part-unicode-12.0.0-escaped.js
part-unicode-13.0.0.js
part-unicode-13.0.0-escaped.js
part-unicode-5.2.0.js
part-unicode-5.2.0-escaped.js
part-unicode-6.0.0.js
part-unicode-6.1.0.js
part-unicode-7.0.0.js
part-unicode-7.0.0-escaped.js
part-unicode-8.0.0.js
part-unicode-8.0.0-escaped.js
part-unicode-9.0.0.js
part-unicode-9.0.0-escaped.js
start-unicode-10.0.0.js
start-unicode-10.0.0-escaped.js
start-unicode-11.0.0.js
start-unicode-11.0.0-escaped.js
start-unicode-12.0.0.js
start-unicode-12.0.0-escaped.js
start-unicode-13.0.0.js
start-unicode-13.0.0-escaped.js
start-unicode-5.2.0.js
start-unicode-5.2.0-escaped.js
start-unicode-6.0.0.js
start-unicode-6.1.0.js
start-unicode-6.1.0-escaped.js
start-unicode-7.0.0.js
start-unicode-7.0.0-escaped.js
start-unicode-8.0.0.js
start-unicode-8.0.0-escaped.js
start-unicode-9.0.0.js
start-zwj-escaped.js
start-zwnj-escaped.js
start-unicode-9.0.0-escaped.js
vertical-tilde-continue.js
vertical-tilde-continue-escaped.js
vertical-tilde-start.js
Expand All @@ -5101,11 +5118,7 @@ language/identifiers 28/188 (14.89%)

language/keywords 0/25 (0.0%)

language/line-terminators 4/41 (9.76%)
S7.3_A6_T1.js
S7.3_A6_T2.js
S7.3_A6_T3.js
S7.3_A6_T4.js
language/line-terminators 0/41 (0.0%)

language/literals 96/434 (22.12%)
bigint/numeric-separators/numeric-separator-literal-nonoctal-08-err.js non-strict
Expand Down Expand Up @@ -5152,12 +5165,7 @@ language/literals 96/434 (22.12%)

~language/module-code

language/punctuators 5/11 (45.45%)
S7.7_A2_T1.js
S7.7_A2_T2.js
S7.7_A2_T3.js
S7.7_A2_T4.js
S7.7_A2_T5.js
language/punctuators 0/11 (0.0%)

language/reserved-words 2/27 (7.41%)
await-module.js {unsupported: [module]}
Expand Down Expand Up @@ -6301,11 +6309,6 @@ language/types 9/113 (7.96%)
undefined/S8.1_A3_T1.js
undefined/S8.1_A3_T2.js non-strict

language/white-space 7/42 (16.67%)
language/white-space 2/42 (4.76%)
mongolian-vowel-separator.js {unsupported: [u180e]}
mongolian-vowel-separator-eval.js {unsupported: [u180e]}
S7.2_A5_T1.js
S7.2_A5_T2.js
S7.2_A5_T3.js
S7.2_A5_T4.js
S7.2_A5_T5.js

0 comments on commit 90ac409

Please sign in to comment.