From: Adam Bozanich Date: 2007-04-27T00:18:47+09:00 Subject: Re: [patch] gsub with backslash characters in replacement string ------=_Part_120569_4010838.1177600722663 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 4/26/07, Yukihiro Matsumoto wrote: > > Hi, > > In message "Re: [patch] gsub with backslash characters in replacement > string" > on Thu, 26 Apr 2007 17:09:42 +0900, "Adam Bozanich" > writes: > > |Hello, spotted this one the other day: > | > |irb(main):001:0> '\\'.gsub('\\','\\\\') > |=> "\\" > |irb(main):002:0> '\\'.gsub('\\','\\\\\\') > |=> "\\\\" > | > |The following patch seems to fix things on my system > > It was intentional to escape backslashes in replacement string. > If it were a bug, how do we escape backslashes? Any idea? > > matz. > > Not sure that I'm understanding you here. let's try again. test.rb: 1.upto(6) do |x| print "a".gsub("a","\\"*x).size , " " end print "a".gsub("a","\n") before patch output is: 1 1 2 2 3 3 after patch output is: 1 2 3 4 5 6 Note that the newline works in both cases. -Adam ------=_Part_120569_4010838.1177600722663 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 4/26/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
Hi,

In message "Re: [patch] gsub with backslash characters in replacement string"
    on Thu, 26 Apr 2007 17:09:42 +0900, "Adam Bozanich" < adam.boz@gmail.com > writes:

|Hello, spotted this one the other day:
|
|irb(main):001:0> '\\'.gsub('\\','\\\\')
|=> "\\"
|irb(main):002:0> '\\'.gsub('\\','\\\\\\')
|=> "\\\\"
|
|The following patch seems to fix things on my system

It was intentional to escape backslashes in replacement string.
If it were a bug, how do we escape backslashes?  Any idea?

                                                        matz.


Not sure that I'm understanding you here.

let's try again.

test.rb:

1.upto(6) do |x|
    print "a".gsub("a","\\"*x).size , " "
end

print "a".gsub("a","\n")

before patch output is:
1 1 2 2 3 3

after patch output is:
1 2 3 4 5 6

Note that the newline works in both cases.

-Adam
------=_Part_120569_4010838.1177600722663--