1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

string.c: fix for \K

* string.c (str_gsub): use BEG(0) for whole matched position not
  return value from rb_reg_search(), for \K matching.
  [ruby-dev:47694] [Bug #8856]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-09-04 02:13:42 +00:00
parent 90cbcbe68b
commit b31965cb43
3 changed files with 13 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Wed Sep 4 11:13:40 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_gsub): use BEG(0) for whole matched position not
return value from rb_reg_search(), for \K matching.
[ruby-dev:47694] [Bug #8856]
Wed Sep 4 11:11:37 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (SOLIBS): LIBRUBY_SO also needs linking with gmp, to

View file

@ -4079,7 +4079,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
if (OBJ_TAINTED(val)) tainted = 1;
len = beg - offset; /* copy pre-match substr */
len = beg0 - offset; /* copy pre-match substr */
if (len) {
rb_enc_str_buf_cat(dest, cp, len, str_enc);
}

View file

@ -500,6 +500,12 @@ class TestRegexp < Test::Unit::TestCase
assert_equal('foo[\z]baz', "foobarbaz".sub!(/(b..)/, '[\z]'))
end
def test_regsub_K
bug8856 = '[ruby-dev:47694] [Bug #8856]'
result = "foobarbazquux/foobarbazquux".gsub(/foo\Kbar/, "")
assert_equal('foobazquux/foobazquux', result, bug8856)
end
def test_KCODE
assert_nil($KCODE)
assert_nothing_raised { $KCODE = nil }