Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some backslashes are dropped from heredocs #374

Open
akimd opened this issue Jul 11, 2024 · 1 comment
Open

Some backslashes are dropped from heredocs #374

akimd opened this issue Jul 11, 2024 · 1 comment

Comments

@akimd
Copy link

akimd commented Jul 11, 2024

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!

@mbj
Copy link
Owner

mbj commented Jul 12, 2024

Its very likely this is solved by #366, will test it. Sadly #366 is not ready yet as its a deeper refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants