Gsub oddity?

Hi,

“\000”.gsub("\000") { “\000” }

=> “\000”

“\000”.gsub("\000", “\000”)

=> “\00000”

I expected both to return the same result.
Just tell me it’s not a bug and I’m happy :slight_smile:

Regards,

Michael

Just tell me it's not a bug and I'm happy :slight_smile:

This is not a bug :slight_smile:

svg% ruby -e 'p "\000".gsub("\000", "\\&00")'
"\00000"
svg%

Guy Decoux

Not a bug :slight_smile:

When used in an argument rather than in a block, \0 inserts the matched
string. So gsub(“\000”, “\000”) is really saying “replace any null
characters with themselves followed by two zeros”.

The block form does not interpolate backslashed matches.

cheers,
–Mark

···

On Apr 24, 2004, at 10:10 AM, Michael Neumann wrote:

Hi,

“\000”.gsub(“\000”) { “\000” }

=> “\000”

“\000”.gsub(“\000”, “\000”)

=> “\00000”

I expected both to return the same result.
Just tell me it’s not a bug and I’m happy :slight_smile: