mirror of
https://github.com/ruby/ruby.git
synced 2026-08-03 11:18:06 +08:00
[ruby/prism] Fix parser translator with trailing backslash in %W /%I array
https://docs.ruby-lang.org/en/master/syntax/literals_rdoc.html#label-25w+and+-25W-3A+String-Array+Literals > %W allow escape sequences described in Escape Sequences. However the continuation line <newline> is not usable because it is interpreted as the escaped newline described above. https://github.com/ruby/prism/commit/f5c7460ad5
This commit is contained in:
parent
4e5c8c19a7
commit
3071c5d04c
@ -425,7 +425,12 @@ module Prism
|
||||
end
|
||||
|
||||
current_string << unescape_string(value, quote_stack.last)
|
||||
if (backslash_count = token.value[/(\\{1,})\n/, 1]&.length).nil? || backslash_count.even? || !interpolation?(quote_stack.last)
|
||||
relevant_backslash_count = if quote_stack.last.start_with?("%W", "%I")
|
||||
0 # the last backslash escapes the newline
|
||||
else
|
||||
token.value[/(\\{1,})\n/, 1]&.length || 0
|
||||
end
|
||||
if relevant_backslash_count.even? || !interpolation?(quote_stack.last)
|
||||
tokens << [:tSTRING_CONTENT, [current_string, range(start_offset, start_offset + current_length)]]
|
||||
break
|
||||
end
|
||||
|
||||
@ -99,6 +99,34 @@ bar)
|
||||
d
|
||||
]
|
||||
|
||||
%w[
|
||||
foo\nbar baz\n\n\
|
||||
bat\n\\\n\foo
|
||||
]
|
||||
|
||||
%W[
|
||||
foo\nbar baz\n\n\
|
||||
bat\n\\\n\foo
|
||||
]
|
||||
|
||||
%w[foo\
|
||||
bar
|
||||
baz\\
|
||||
bat
|
||||
1\n
|
||||
2
|
||||
3\\n
|
||||
]
|
||||
|
||||
%W[foo\
|
||||
bar
|
||||
baz\\
|
||||
bat
|
||||
1\n
|
||||
2
|
||||
3\\n
|
||||
]
|
||||
|
||||
%W[f\u{006f 006f}]
|
||||
|
||||
%W[a b#{c}d e]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user