diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 355e7a8aff..cab785d7c6 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -162,6 +162,12 @@ class ErrorsTest < Test::Unit::TestCase ] end + def test_cr_without_lf_in_percent_expression + assert_errors expression("%\r"), "%\r", [ + ["Invalid %% token", 0..3], + ] + end + def test_1_2_3 assert_errors expression("(1, 2, 3)"), "(1, 2, 3)", [ ["Expected to be able to parse an expression.", 2..2], diff --git a/yarp/yarp.c b/yarp/yarp.c index 8f93611d6b..65c9e959fd 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -6186,7 +6186,9 @@ parser_lex(yp_parser_t *parser) { yp_newline_list_check_append(&parser->newline_list, parser->current.end); parser->current.end++; - LEX(YP_TOKEN_STRING_BEGIN); + if (parser->current.end < parser->end) { + LEX(YP_TOKEN_STRING_BEGIN); + } } switch (*parser->current.end) { @@ -6285,7 +6287,7 @@ parser_lex(yp_parser_t *parser) { // unparseable. In this case we'll just drop it from the parser // and skip past it and hope that the next token is something // that we can parse. - yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, "invalid %% token"); + yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, "Invalid %% token"); goto lex_next_token; } }