Commit graph

2 commits

Author SHA1 Message Date
Aaron Patterson
9181e8bc87 [ruby/prism] Decode %r like % strings
%r regular expressions need to be decoded like strings.  This commit
fixes %r decoding so it works like strings.

85bfd9c0cd
2024-12-12 00:42:44 +00:00
eileencodes
9fe6fd8693 [ruby/prism] Fix percent delimiter strings with crlfs
parse.y treats CRLF as a LF and basically "normalizes" them before
parsing.  That means a string like `%\nfoo\r\n` is actually treated as
`%\nfoo\n` for the purposes of parsing.  This happens on both the
opening side of the percent string as well as on the closing side.  So
for example `%\r\nfoo\n` must be treated as `%\nfoo\n`.

To handle this in Prism, when we start a % string, we check if it starts
with `\r\n`, and then consider the terminator to actually be `\n`.  Then
we check if there are `\r\n` as we lex the string and treat those as
`\n`, but only in the case the start was a `\n`.

Fixes: #3230

[Bug #20938]

e573ceaad6

Co-authored-by: John Hawthorn <jhawthorn@github.com>
Co-authored-by: eileencodes <eileencodes@gmail.com>
Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-12-11 23:06:32 +00:00