Skip to content

Commit

Permalink
take care of eof when parsing templates (fixes mozilla#1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jun 8, 2023
1 parent 5a0e5b3 commit bde1f8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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
11 changes: 10 additions & 1 deletion 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 Expand Up @@ -1437,7 +1446,7 @@ public EvaluatorException runtimeError(
AstRoot script = null;
try {
script = p.parse(string, null, 0);
} catch (EvaluatorException e) {
} catch (Exception e) {
if (errors == null) {
// EvaluationExceptions should not occur when we aren't expecting
// errors.
Expand Down

0 comments on commit bde1f8a

Please sign in to comment.