ruby-changes:65289
From: Shugo <ko1@a...>
Date: Fri, 19 Feb 2021 16:41:52 +0900 (JST)
Subject: [ruby-changes:65289] 5de38c41ae (master): ripper: fix a bug of Ripper::Lexer with syntax error and heredoc [Bug #17644]
https://git.ruby-lang.org/ruby.git/commit/?id=5de38c41ae From 5de38c41ae7bf17ae599fdfa9f8face87f16d8bb Mon Sep 17 00:00:00 2001 From: Shugo Maeda <shugo@r...> Date: Fri, 19 Feb 2021 16:38:34 +0900 Subject: ripper: fix a bug of Ripper::Lexer with syntax error and heredoc [Bug #17644] --- ext/ripper/lib/ripper/lexer.rb | 2 +- test/ripper/test_lexer.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb index 8222684..f6051c6 100644 --- a/ext/ripper/lib/ripper/lexer.rb +++ b/ext/ripper/lib/ripper/lexer.rb @@ -136,7 +136,7 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L136 end @buf.flatten! unless (result = @buf).empty? - result.concat(@buf) until (@buf = []; super(); @buf.empty?) + result.concat(@buf) until (@buf = []; super(); @buf.flatten!; @buf.empty?) end result end diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb index 79cb194..d0389f7 100644 --- a/test/ripper/test_lexer.rb +++ b/test/ripper/test_lexer.rb @@ -216,4 +216,16 @@ class TestRipper::Lexer < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_lexer.rb#L216 end end end + + def test_lex_with_syntax_error_and_heredo + bug = '[Bug #17644]' + s = <<~EOF + foo + end + <<~EOS + bar + EOS + EOF + assert_equal([[5, 0], :on_heredoc_end, "EOS\n", state(:EXPR_BEG)], Ripper.lex(s).last, bug) + end end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/