aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-04 02:13:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-04 02:13:42 +0000
commitb31965cb43e8f6117435acf6f676cb9a4417afff (patch)
tree802956e420049a68d2ebded387ed25290399df0a
parent90cbcbe68b148ae929610ca85afd5c3318216d4d (diff)
downloadruby-b31965cb43e8f6117435acf6f676cb9a4417afff.tar.gz
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
-rw-r--r--ChangeLog6
-rw-r--r--string.c2
-rw-r--r--test/ruby/test_regexp.rb6
3 files changed, 13 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index c9f5c7127a..ae6125fa9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/string.c b/string.c
index 70cedf204b..4bc26df81e 100644
--- a/string.c
+++ b/string.c
@@ -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);
}
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 5982d23e1f..7937fe8867 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -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 }