[BUG] greedy gsub

this looks like a bug to me:

~/eg/ruby > cat bug.rb

greedy gsub works fine a bos

k1, p1 = ‘=foo’, %r/^(=*)/
p(p1.match(k1).to_a)
p(k1.gsub(p1, ‘!’))

greedy gsub fails at eos

k0, p0 = ‘foo=’, %r/(=*)$/
p(p0.match(k0).to_a)
p(k0.gsub(p0, ‘!’))

~/eg/ruby > ruby bug.rb

[“=”, “=”]
“!foo”
[“=”, “=”]
“foo!!”

~/eg/ruby > ruby -v
ruby 1.8.0 (2003-10-15) [i686-linux]

-a

···

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

this looks like a bug to me:

no, no

  k0, p0 = 'foo=', %r/(=*)$/
  p(p0.match(k0).to_a)
  p(k0.gsub(p0, '!'))

first match because there is `=' at the end
second match because the empty patterm /=*/ match at end

Guy Decoux