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

ruby-changes:45301

From: shugo <ko1@a...>
Date: Thu, 19 Jan 2017 17:13:12 +0900 (JST)
Subject: [ruby-changes:45301] shugo:r57374 (trunk): string.c: rindex(//) should set $~.

shugo	2017-01-19 17:13:03 +0900 (Thu, 19 Jan 2017)

  New Revision: 57374

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57374

  Log:
    string.c: rindex(//) should set $~.
    
    This seems a bug introduced by r520 (1.4.0).  [ruby-core:79110] [Bug #13135]

  Modified files:
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: string.c
===================================================================
--- string.c	(revision 57373)
+++ string.c	(revision 57374)
@@ -3516,10 +3516,8 @@ rb_str_rindex_m(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/string.c#L3516
 	pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
 			 enc, single_byte_optimizable(str));
 
-	if (!RREGEXP_PTR(sub) || RREGEXP_SRC_LEN(sub)) {
-	    pos = rb_reg_search(sub, str, pos, 1);
-	    pos = rb_str_sublen(str, pos);
-	}
+	pos = rb_reg_search(sub, str, pos, 1);
+	pos = rb_str_sublen(str, pos);
 	if (pos >= 0) return LONG2NUM(pos);
 	break;
 
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 57373)
+++ test/ruby/test_string.rb	(revision 57374)
@@ -1227,6 +1227,9 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1227
 
     assert_nil("foo".rindex(//, -100))
     assert_nil($~)
+
+    assert_equal(3, "foo".rindex(//))
+    assert_equal([3, 3], $~.offset(0))
   end
 
   def test_rjust

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

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