Skip to content

Some backslashes are dropped from heredocs #374

Open
@akimd

Description

Hi Markus,

When there is an interpolation in the heredoc, it comes out underescaped.

require 'unparser'

ast = Unparser.parse(<<~'OUTER')
    <<~RUBY
        validates :#{field_sid}, format: {
            with: /\\A\\-+(\\w+\\-+)|(\\w+\\.)\\Z/i
         }
    RUBY
OUTER
p ast
puts Unparser.unparse(ast)
s(:dstr,
  s(:str, "validates :"),
  s(:begin,
    s(:send, nil, :field_sid)),
  s(:str, ", format: {\n"),
  s(:str, "    with: /\\A\\-+(\\w+\\-+)|(\\w+\\.)\\Z/i\n"),
  s(:str, " }\n"))
<<-HEREDOC
validates :#{field_sid}, format: {
    with: /\A\-+(\w+\-+)|(\w+\.)\Z/i
 }
HEREDOC

All the backslashes should be doubled. And they are if I remove the interpolation.

Cheers!

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions