Skip to content

Commit

Permalink
ripper_state_lex.rb: chomp CR
Browse files Browse the repository at this point in the history
* lib/rdoc/parser/ripper_state_lex.rb (RDoc::Parser::RipperStateLex):
  chomp newline, including CR, from here document terminator.

Closes: #694
Closes: #697
Closes: #705
  • Loading branch information
nobu authored and aycabta committed Jun 7, 2019
1 parent c5569e7 commit 5f9603f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rdoc/parser/ripper_state_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ def get_squashed_tk
private def heredoc_end?(name, indent, tk)
result = false
if :on_heredoc_end == tk[:kind] then
tk_name = (indent ? tk[:text].gsub(/^ *(.+)\n?$/, '\1') : tk[:text].gsub(/\n\z/, ''))
tk_name = tk[:text].chomp
tk_name.lstrip! if indent
if name == tk_name
result = true
end
Expand Down
15 changes: 15 additions & 0 deletions test/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,21 @@ def blah()
assert_equal expected, markup_code
end

def test_parse_heredoc_end
code = "A = <<eos\n""OK\n""eos\n"
util_parser code
@parser.parse_statements @top_level
@parser.scan
c = @top_level.classes.first.constants.first
assert_equal("A", c.name)

util_parser code.gsub(/$/, "\r")
@parser.parse_statements @top_level
@parser.scan
c = @top_level.classes.first.constants.first
assert_equal("A", c.name)
end

def test_parse_statements_method_oneliner_with_regexp
util_parser <<RUBY
class Foo
Expand Down

0 comments on commit 5f9603f

Please sign in to comment.