Skip to content

Commit

Permalink
take care of eof when parsing templates (fixes #1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jun 8, 2023
1 parent 5a0e5b3 commit 23c45e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/org/mozilla/javascript/TokenStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,12 @@ int readTemplateLiteral(boolean isTaggedLiteral) throws IOException {
escapeVal = -1;
break;
}

c = getTemplateLiteralChar();
if (c == EOF_CHAR) {
parser.reportError("msg.syntax");
return Token.ERROR;
}

if (c == '}') {
break;
Expand Down
9 changes: 9 additions & 0 deletions testsrc/org/mozilla/javascript/tests/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,15 @@ public void es6GeneratorNot() {
new String[] {"missing ( before function parameters."});
}

@Test
public void oomOnInvalidInput() {
// parse();
expectParseErrors(
"`\\u{8",
new String[] {"syntax error"});

}

private void expectParseErrors(String string, String[] errors) {
parse(string, errors, null, false);
}
Expand Down

0 comments on commit 23c45e2

Please sign in to comment.