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

ruby-changes:23096

From: nobu <ko1@a...>
Date: Tue, 27 Mar 2012 13:14:04 +0900 (JST)
Subject: [ruby-changes:23096] nobu:r35146 (trunk): * string.c (str_new_empty): should copy also the encoding as an

nobu	2012-03-27 13:13:54 +0900 (Tue, 27 Mar 2012)

  New Revision: 35146

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

  Log:
    * string.c (str_new_empty): should copy also the encoding as an
      empty substring.  [ruby-dev:45441][Bug #6206]

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35145)
+++ ChangeLog	(revision 35146)
@@ -1,3 +1,8 @@
+Tue Mar 27 13:13:51 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (str_new_empty): should copy also the encoding as an
+	  empty substring.  [ruby-dev:45441][Bug #6206]
+
 Mon Mar 26 23:43:04 2012  Shugo Maeda  <shugo@r...>
 
 	* lib/net/ftp.rb (parse227, parse228, parse229): don't use $~.
Index: string.c
===================================================================
--- string.c	(revision 35145)
+++ string.c	(revision 35146)
@@ -726,6 +726,7 @@
 str_new_empty(VALUE str)
 {
     VALUE v = rb_str_new5(str, 0, 0);
+    rb_enc_copy(v, str);
     OBJ_INFECT(v, str);
     return v;
 }
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 35145)
+++ test/ruby/test_string.rb	(revision 35146)
@@ -1174,6 +1174,12 @@
 
     assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug")
 
+    bug6206 = '[ruby-dev:45441]'
+    Encoding.list.each do |enc|
+      next unless enc.ascii_compatible?
+      s = S("a:".force_encoding(enc))
+      assert_equal([enc]*2, s.split(":", 2).map(&:encoding), bug6206)
+    end
   end
 
   def test_squeeze
@@ -1824,6 +1830,13 @@
     assert_raise(TypeError) { "hello".partition(1) }
     def (hyphen = Object.new).to_str; "-"; end
     assert_equal(%w(foo - bar), "foo-bar".partition(hyphen), '[ruby-core:23540]')
+
+    bug6206 = '[ruby-dev:45441]'
+    Encoding.list.each do |enc|
+      next unless enc.ascii_compatible?
+      s = S("a:".force_encoding(enc))
+      assert_equal([enc]*3, s.partition("|").map(&:encoding), bug6206)
+    end
   end
 
   def test_rpartition
@@ -1832,6 +1845,13 @@
     assert_raise(TypeError) { "hello".rpartition(1) }
     def (hyphen = Object.new).to_str; "-"; end
     assert_equal(%w(foo - bar), "foo-bar".rpartition(hyphen), '[ruby-core:23540]')
+
+    bug6206 = '[ruby-dev:45441]'
+    Encoding.list.each do |enc|
+      next unless enc.ascii_compatible?
+      s = S("a:".force_encoding(enc))
+      assert_equal([enc]*3, s.rpartition("|").map(&:encoding), bug6206)
+    end
   end
 
   def test_setter

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

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