mbj / unparser

Turn Ruby AST into semantically equivalent Ruby source
MIT License
309 stars 52 forks source link

Broken code when an op_asgn node contains a string with interpolation and the string contains a linefeed. #350

Closed vidarh closed 11 months ago

vidarh commented 11 months ago

If you parse code that produces an op_asgn node, such as e.g. a statement containing "+=" or "&=" etc., and the right hand side of that contains a string, and the string contains interpolation and a linefeed, the output ends up replacing the right hand side with a "<<- HEREDOC" but never outputs the HEREDOC.

Simplest test case I've found:

y += "#{42}\n"

Test program:

require 'parser/current'
require 'unparser'

puts Unparser.unparse(Unparser.parse('y += "#{42}\n"'))

Output:

y += <<- HEREDOC
vidarh commented 11 months ago

Found this "in the wild" when trying to parse toml-rb (lib/toml-rb/dumper.rb) which has a more complex use to test against.

vidarh commented 11 months ago

Looking at #249 it seems likely to be a similar or the same issue.

vidarh commented 11 months ago

Pull request: https://github.com/mbj/unparser/pull/351

mbj commented 11 months ago

@vidarh Fix released in v0.6.10.