diff options
author | Earlopain <[email protected]> | 2025-01-20 15:49:06 +0100 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2025-03-18 13:36:53 -0400 |
commit | ac728389e219480dd678a01e6f91f96098d3b6d6 (patch) | |
tree | c419636b411b0637028b38322898ead602a1c847 /lib | |
parent | 0fcb7fc21d1923a61ffe4d127e6e72cc55560972 (diff) |
[ruby/prism] Fix parser translator edge-case when multiline string ends with \n
When the line contains no real newline but contains unescaped ones, then there will be one less entry
https://github.com/ruby/prism/commit/4ef093b600
Diffstat (limited to 'lib')
-rw-r--r-- | lib/prism/translation/parser/compiler.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index 91995efc43..83cbe6e0c9 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -2260,7 +2260,9 @@ module Prism .each do |lines| escaped_lengths << lines.sum(&:bytesize) unescaped_lines_count = lines.sum do |line| - line.scan(/(\\*)n/).count { |(backslashes)| backslashes&.length&.odd? || false } + count = line.scan(/(\\*)n/).count { |(backslashes)| backslashes&.length&.odd? } + count -= 1 if !line.end_with?("\n") && count > 0 + count end extra = 1 extra = lines.count if percent_array # Account for line continuations in percent arrays |