From: James French Date: 2012-02-28T23:41:20+09:00 Subject: [ruby-core:43003] Bug in sub/gsub? --_000_950618E0D00138499BE7CC487EBF646D6709C0D75FWOODCHUCKNMlo_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, I just got caught when trying to do a simple text replacement where the rep= lacement string (a dynamic string, not a string literal) contained '\3'. ruby -e "puts 'foobar'.gsub('bar', '\3')" gives 'foo', not 'foo\3' as I expected. Its doing this because its interpreting \3 as a regex back reference. But w= hy is it doing this? Neither parameter is a regex, therefore it should trea= t it as a literal IMO. If this is not considered a bug then is definitely a violation of the princ= iple of least surprise. Using ruby 1.9.3-p125. Cheers, James --_000_950618E0D00138499BE7CC487EBF646D6709C0D75FWOODCHUCKNMlo_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

I just got= caught when trying to do a simple text replacement where the replacement s= tring (a dynamic string, not a string literal) contained ‘\3’.<= o:p>

 

ruby –e “puts ‘foobar’.gsub(‘bar’, &#= 8216;\3’)”

 =

gives ‘foo’, not ‘foo\3’ a= s I expected.

 

Its doing this because its interpreting \3 as a regex back = reference. But why is it doing this? Neither parameter is a regex, therefor= e it should treat it as a literal IMO.

<= o:p> 

If this is not considered a bug th= en is definitely a violation of the principle of least surprise.

 

Using r= uby 1.9.3-p125.

 

Cheers,

James

= --_000_950618E0D00138499BE7CC487EBF646D6709C0D75FWOODCHUCKNMlo_--