Skip to content

Commit

Permalink
* lexer.rl: handle \r in middle of a line as mere whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Nov 12, 2013
1 parent 34b95ed commit fecc7d2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
9 changes: 0 additions & 9 deletions TODO.md

This file was deleted.

5 changes: 5 additions & 0 deletions lib/parser/lexer.rl
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,11 @@ class Parser::Lexer
if literal.heredoc?
line = tok(@herebody_s, @ts).gsub(/\r+$/, '')

if version?(18, 19, 20)
# See ruby:c48b4209c
line = line.gsub(/\r.*$/, '')
end

# Try ending the heredoc with the complete most recently
# scanned line. @herebody_s always refers to the start of such line.
if literal.nest_and_try_closing(line, @herebody_s, @ts)
Expand Down
14 changes: 14 additions & 0 deletions test/test_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,20 @@ def test_whitespace_end
:tINTEGER, 1)
end

def test_whitespace_cr
setup_lexer(20)
assert_scanned("<<E\nfoo\nE\rO",
:tSTRING_BEG, '"',
:tSTRING_CONTENT, "foo\n",
:tSTRING_END, 'E',
:tNL, nil)

setup_lexer(21)
refute_scanned("<<E\nfoo\nE\rO",
:tSTRING_BEG, '"',
:tSTRING_CONTENT, "foo\n")
end

#
# Tests for bugs.
#
Expand Down

0 comments on commit fecc7d2

Please sign in to comment.