1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ripper: fix a bug of Ripper::Lexer with syntax error and heredoc [Bug #17644]

This commit is contained in:
Shugo Maeda 2021-02-19 16:38:34 +09:00
parent 7b9476fbfa
commit 5de38c41ae
No known key found for this signature in database
GPG key ID: 2DFE34085E97CE47
2 changed files with 13 additions and 1 deletions

View file

@ -136,7 +136,7 @@ class Ripper
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

View file

@ -216,4 +216,16 @@ class TestRipper::Lexer < Test::Unit::TestCase
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