Project

General

Profile

Actions

Bug #2547

closed

error when interpolating a string containing a single backslash into a regexp

Added by coatl (caleb clausen) over 14 years ago. Updated about 13 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.1p376 (2009-12-07 revision 26040) [x86_64-linux]
Backport:
[ruby-core:27374]

Description

=begin
An error is raised if an interpolation in a regexp contains a string containing a single backslash. This case used to work just great in ruby 1.8. For example:

$ ruby19 -e 'a="\"; p /#{a}y/'
-e:1:in `': too short escape sequence (ArgumentError)

Note that if the string literal is inlined directly into the interpolation, the error does not happen. I'd guess that ruby optimizes this case away at parse time, and thus sidesteps the error:

$ ruby19 -e 'p /#{"\"}y/'
/\y/

I've tested this in 1.9.1; presumably 1.9.2 has the same behavior, but I don't have a 1.9.2 readily available.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0