diff options
-rw-r--r-- | lexer.c | 10 | ||||
-rw-r--r-- | tests/custom/03_bugs/18_hang_on_line_comments_at_eof | 31 |
2 files changed, 38 insertions, 3 deletions
@@ -359,9 +359,6 @@ parse_comment(uc_lexer *lex) const char *ptr, *end; size_t elen; - if (!buf_remaining(lex)) - return emit_op(lex, lex->lastoff, TK_ERROR, ucv_string_new("Unterminated comment")); - if (!strcmp(tok->u.pat, "//")) { end = "\n"; elen = 1; @@ -381,6 +378,13 @@ parse_comment(uc_lexer *lex) buf_consume(lex, ptr - lex->bufstart); + if (lex->eof) { + lex->state = UT_LEX_EOF; + + if (elen == 2) + return emit_op(lex, lex->lastoff, TK_ERROR, ucv_string_new("Unterminated comment")); + } + return NULL; } diff --git a/tests/custom/03_bugs/18_hang_on_line_comments_at_eof b/tests/custom/03_bugs/18_hang_on_line_comments_at_eof new file mode 100644 index 0000000..957ed47 --- /dev/null +++ b/tests/custom/03_bugs/18_hang_on_line_comments_at_eof @@ -0,0 +1,31 @@ +When parsing a comment near EOF, or a comment escaping the end +of an expression block, the lexer did end up in an infinite loop. + +-- Expect stderr -- +Syntax error: Expecting expression +In line 1, byte 9: + + `{{ // }}` + ^-- Near here + + +-- End -- + +-- Testcase -- +{{ // }} +-- End -- + + +-- Expect stderr -- +Syntax error: Unterminated comment +In line 1, byte 4: + + `{{ /* }}` + ^-- Near here + + +-- End -- + +-- Testcase -- +{{ /* }} +-- End -- |