Forum: Ruby-core [Bug #1695] String interpolation Issue with escape characters inside an in-string evaluated statemen

Posted by Jason Pearlman (Guest)
on 2009-06-26 17:25
(Received via mailing list)
Bug #1695: String interpolation Issue with escape characters inside an 
in-string evaluated statement
http://redmine.ruby-lang.org/issues/show/1695

Author: Jason Pearlman
Status: Open, Priority: Normal
Category: core
ruby -v: ruby 1.9.1p129 (2009-05-12 revision 23412) [x86_64-linux]

Apologies if this has already been addressed but I could not find 
anything:

# Alone, works fine
>> 'a'.gsub("'",'\\\'')
=> "a"

# Inside a string in #{} - bombs
>> "hi #{'a'.gsub("'",'\\\'')}"
[just waits for another "]
"
SyntaxError: compile error
(irb):20: unterminated string meets end of file
        from (irb):20
Posted by Roger Pack (Guest)
on 2009-06-26 17:34
(Received via mailing list)
> # Inside a string in #{} - bombs
>>> "hi #{'a'.gsub("'",'\\\'')}"
> [just waits for another "]
> "
> SyntaxError: compile error
> (irb):20: unterminated string meets end of file
>        from (irb):20

Looks like a bug in irb's internal "am I done with a complete
expression" parser, since it works if within a .rb script.
=r
Posted by Run Paint Run Run (Guest)
on 2009-06-26 17:55
(Received via mailing list)
Issue #1695 has been updated by Run Paint Run Run.


Is the problem not simply the use of <"> inside the #gsub?

Ruby expects delimiters to be matched. Your second double quotation mark 
terminates the String you began with the first; so the single quotation 
mark that immediately follows that is assumed to begin a new string. 
IOW, Ruby regards <"hi #{'a'.gsub("> as your first string, which is 
followed by <'",'>, which is followed by <\\\'')}">. Hence the syntax 
error.

If you want to do all of that on the same line, why not use alternative 
delimiters? For example:

%!hi #{'a'.gsub("'",'\\\'')}!  #=> "hi a"
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1695
Posted by Jason Pearlman (Guest)
on 2009-06-26 18:17
(Received via mailing list)
Issue #1695 has been updated by Jason Pearlman.


Thanks! If anything this seems more on the IRB side of things.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1695
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.