diff options
| author | Mike Dalessio <mike.dalessio@gmail.com> | 2023-08-20 16:38:49 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-08-21 19:00:52 +0000 |
| commit | 461f8eaba74a7475bf97921e3ed45b63b126a190 (patch) | |
| tree | 484b0a2d61a1b70f3a4f69de94aa10aedaf65bfd | |
| parent | ca6db02c2a305bc990c144439996abfe984a6c5a (diff) | |
[ruby/yarp] fix: parsing a '%' expression with a CR but not a newline
Previously this failed an assertion and aborted.
https://github.com/ruby/yarp/commit/a037d942a8
| -rw-r--r-- | test/yarp/errors_test.rb | 6 | ||||
| -rw-r--r-- | yarp/yarp.c | 6 |
2 files changed, 10 insertions, 2 deletions
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; } } |
