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

ruby-changes:47881

From: nobu <ko1@a...>
Date: Sun, 24 Sep 2017 03:28:13 +0900 (JST)
Subject: [ruby-changes:47881] nobu:r60000 (trunk): dup String#partition return value

nobu	2017-09-23 16:09:05 +0900 (Sat, 23 Sep 2017)

  New Revision: 60000

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

  Log:
    dup String#partition return value
    
    * string.c (rb_str_partition): return duplicated receiver, when no
      splits.  [ruby-core:82911] [Bug#13925]
    
    Author:    Seiei Miyagi <hanachin@g...>

  Modified files:
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: string.c
===================================================================
--- string.c	(revision 59999)
+++ string.c	(revision 60000)
@@ -9124,7 +9124,7 @@ rb_str_partition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L9124
 	pos = rb_reg_search(sep, str, 0, 0);
 	if (pos < 0) {
 	  failed:
-	    return rb_ary_new3(3, str, str_new_empty(str), str_new_empty(str));
+	    return rb_ary_new3(3, rb_str_dup(str), str_new_empty(str), str_new_empty(str));
 	}
 	sep = rb_str_subpat(str, sep, INT2FIX(0));
 	if (pos == 0 && RSTRING_LEN(sep) == 0) goto failed;
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 59999)
+++ test/ruby/test_string.rb	(revision 60000)
@@ -2420,7 +2420,12 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L2420
     end
 
     assert_equal(["\u30E6\u30FC\u30B6", "@", "\u30C9\u30E1.\u30A4\u30F3"],
-      "\u30E6\u30FC\u30B6@\u30C9\u30E1.\u30A4\u30F3".partition(/[@.]/))
+                 "\u30E6\u30FC\u30B6@\u30C9\u30E1.\u30A4\u30F3".partition(/[@.]/))
+
+    bug = '[ruby-core:82911]'
+    hello = "hello"
+    hello.partition("hi").map(&:upcase!)
+    assert_equal("hello", hello, bug)
   end
 
   def test_rpartition

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

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