[前][次][番号順一覧][スレッド一覧]

ruby-changes:30741

From: nobu <ko1@a...>
Date: Wed, 4 Sep 2013 11:13:49 +0900 (JST)
Subject: [ruby-changes:30741] nobu:r42820 (trunk): string.c: fix for \K

nobu	2013-09-04 11:13:42 +0900 (Wed, 04 Sep 2013)

  New Revision: 42820

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42820

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_regexp.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42819)
+++ ChangeLog	(revision 42820)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Sep  4 11:13:40 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* configure.in (SOLIBS): LIBRUBY_SO also needs linking with gmp, to
Index: string.c
===================================================================
--- string.c	(revision 42819)
+++ string.c	(revision 42820)
@@ -4079,7 +4079,7 @@ str_gsub(int argc, VALUE *argv, VALUE st https://github.com/ruby/ruby/blob/trunk/string.c#L4079
 
 	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);
         }
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 42819)
+++ test/ruby/test_regexp.rb	(revision 42820)
@@ -500,6 +500,12 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L500
     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 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]