File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
lib/prism/translation/parser Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -2040,6 +2040,13 @@ def visit_block(call, block)
20402040 end
20412041 end
20422042
2043+ # The parser gem automatically converts \r\n to \n, meaning our offsets
2044+ # need to be adjusted to always subtract 1 from the length.
2045+ def chomped_bytesize ( line )
2046+ chomped = line . chomp
2047+ chomped . bytesize + ( chomped == line ? 0 : 1 )
2048+ end
2049+
20432050 # Visit a heredoc that can be either a string or an xstring.
20442051 def visit_heredoc ( node )
20452052 children = Array . new
@@ -2066,14 +2073,14 @@ def visit_heredoc(node)
20662073 if node . opening . end_with? ( "'" )
20672074 escaped . each do |line |
20682075 escaped_lengths << line . bytesize
2069- normalized_lengths << ( line . chomp . bytesize + 1 )
2076+ normalized_lengths << chomped_bytesize ( line )
20702077 end
20712078 else
20722079 escaped
20732080 . chunk_while { |before , after | before . match? ( /(?<!\\ )\\ \r ?\n $/ ) }
20742081 . each do |lines |
20752082 escaped_lengths << lines . sum ( &:bytesize )
2076- normalized_lengths << lines . sum { |line | line . chomp . bytesize + 1 }
2083+ normalized_lengths << lines . sum { |line | chomped_bytesize ( line ) }
20772084 end
20782085 end
20792086
Original file line number Diff line number Diff line change @@ -59,7 +59,6 @@ class ParserTest < TestCase
5959 # These files are either failing to parse or failing to translate, so we'll
6060 # skip them for now.
6161 skip_all = skip_incorrect | [
62- "dash_heredocs.txt" ,
6362 "regex.txt" ,
6463 "regex_char_width.txt" ,
6564 "unescaping.txt" ,
@@ -86,6 +85,7 @@ class ParserTest < TestCase
8685 # output expected by the parser gem, so we'll skip them for now.
8786 skip_tokens = [
8887 "comments.txt" ,
88+ "dash_heredocs.txt" ,
8989 "dos_endings.txt" ,
9090 "embdoc_no_newline_at_end.txt" ,
9191 "heredoc_with_comment.txt" ,
You can’t perform that action at this time.
0 commit comments