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
Escaped backslash at end of line causes newline to be removed in heredocs #789
Comments
This does not appear to be an issue with stabby heredocs ( |
@eugeneotto Thanks for reporting it. The bug is definitely somewhere in https://github.com/whitequark/parser/blob/master/lib/parser/lexer/dedenter.rb. Looks like blindly splitting by I'll try to find some time to fix it. Or feel free to send a PR if you have time. |
I'm working on a pull request for a related problem that seems to fix this issue as well. |
Firstly, this fixes an issue with non-interpolating squiggly heredocs, where line continuation characters should be ignored. Two things were broken: - The line continuation backslash would be removed, as well as the subsequent carriage return - The subsequent line would not be dedented. For example, the following source: ```ruby <<~'END' foo \ bar END ``` Would be parsed as follows: ``` (dstr (str "foo ") (str " bar\n")) ``` With the change, the result is: ``` (dstr (str "foo \\\n") (str "bar\n")) ``` This also fixes an issue with interpolating squiggly heredocs, where an escaped backslash followed by a newline would be interpreted as a line continuation. This is issue #789. In that case, the following source: ```ruby <<~END foo \\ bar END ``` Would (again) be parsed as follows: ``` (dstr (str "foo ") (str " bar\n")) ``` With the change, the result is: ``` (dstr (str "foo \\\n") (str "bar\n")) ```
Fixed in #819:
@eugeneotto Do you need a release? If not it will be released with the next version of Ruby (or once someone asks for release) |
Thank you @iliabylich and @mvz! I can wait for the next version of Ruby, but do appreciate the offer 👍 |
Here is a small script that demonstrates the behavior:
This is the script's output:
This is ruby-parse's output:
The text was updated successfully, but these errors were encountered: