diff options
author | NARUSE, Yui <naruse@airemix.jp> | 2023-02-07 13:46:36 +0900 |
---|---|---|
committer | NARUSE, Yui <naruse@airemix.jp> | 2023-02-07 13:46:36 +0900 |
commit | 7246cd0081ec845e1407484fca10439e7868880b (patch) | |
tree | 16eb5adc7e74a22c3ec924d4d4194437a6c0bf63 | |
parent | 3426ebd0489654f951a8b92efaf5e72b9f43efab (diff) | |
download | ruby-7246cd0081ec845e1407484fca10439e7868880b.tar.gz |
merge revision(s) fad48fefe19cc282a5b209944244a3713359b47f: [Backport #19399]
[Bug #19399] Parsing invalid heredoc inside block parameter
Although this is of course invalid as Ruby code, allow to just parse
and tokenize.
---
ext/ripper/lib/ripper/lexer.rb | 2 +-
test/ripper/test_lexer.rb | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
-rw-r--r-- | ext/ripper/lib/ripper/lexer.rb | 2 | ||||
-rw-r--r-- | test/ripper/test_lexer.rb | 12 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb index 19c59e2ccc..6a3c04af30 100644 --- a/ext/ripper/lib/ripper/lexer.rb +++ b/ext/ripper/lib/ripper/lexer.rb @@ -228,7 +228,7 @@ class Ripper def on_heredoc_end(tok) @buf.push Elem.new([lineno(), column()], __callee__, tok, state()) - @buf = @stack.pop + @buf = @stack.pop unless @stack.empty? end def _push_token(tok) diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb index 27e0007023..8e8a616627 100644 --- a/test/ripper/test_lexer.rb +++ b/test/ripper/test_lexer.rb @@ -252,4 +252,16 @@ world" ] assert_equal(code, Ripper.tokenize(code).join(""), bug) end + + def test_heredoc_inside_block_param + bug = '[Bug #19399]' + code = <<~CODE + a do |b + <<-C + C + | + end + CODE + assert_equal(code, Ripper.tokenize(code).join(""), bug) + end end @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 28 +#define RUBY_PATCHLEVEL 29 #include "ruby/version.h" #include "ruby/internal/abi.h" |