Skip to content

Commit

Permalink
🐞 fix: Fix reserved identifier check for built-in object matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 12, 2024
1 parent fd346fe commit edda2c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public ISwc4jAst matches(JavetSanitizerOptions options, ISwc4jAst node) {
if (!options.getReservedFunctionIdentifierSet().contains(identifier)) {
return node;
}
} else if (options.getReservedIdentifierSet().contains(identifier)) {
break;
} else if (!options.getReservedIdentifierSet().contains(identifier)) {
return node;
} else if (!options.getReservedMutableIdentifierSet().contains(identifier)) {
return node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,32 @@ public void testReservedIdentifiers() {
options.getReservedIdentifierSet().add("$a");
checker.setOptions(options.seal());
assertException(
"const $a = 1; const $b = 1;",
"$a; const $b = 1;",
JavetSanitizerError.IdentifierNotAllowed,
"Identifier $b is not allowed.\n" +
"Source: $b\n" +
"Line: 1\n" +
"Column: 21\n" +
"Start: 20\n" +
"End: 22");
"Column: 11\n" +
"Start: 10\n" +
"End: 12");
assertException(
"$b;",
JavetSanitizerError.IdentifierNotAllowed,
"Identifier $b is not allowed.\n" +
"Source: $b\n" +
"Line: 1\n" +
"Column: 1\n" +
"Start: 0\n" +
"End: 2");
assertException(
"const $a = 1;",
JavetSanitizerError.IdentifierNotAllowed,
"Identifier $a is not allowed.\n" +
"Source: $a\n" +
"Line: 1\n" +
"Column: 7\n" +
"Start: 6\n" +
"End: 8");
}

@Test
Expand Down

0 comments on commit edda2c4

Please sign in to comment.