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 authored and gbrail committed Jun 8, 2023
1 parent 12ed8f6 commit 75ac003
Show file tree
Hide file tree
Showing 2 changed files with 10 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
5 changes: 5 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,11 @@ public void es6GeneratorNot() {
new String[] {"missing ( before function parameters."});
}

@Test
public void oomOnInvalidInput() {
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 75ac003

Please sign in to comment.