diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 1 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 20 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 27 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Fri Mar 30 14:15:40 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * string.c (str_new_empty): should copy also the encoding as an + empty substring. [ruby-dev:45441][Bug #6206] + Fri Mar 30 14:14:36 2012 Tadayoshi Funaba <tadf@dotrb.org> * ext/date/date_core.c (datetime_s_now): [ruby-core:43256]. @@ -725,6 +725,7 @@ static VALUE str_new_empty(VALUE str) { VALUE v = rb_str_new5(str, 0, 0); + rb_enc_copy(v, str); OBJ_INFECT(v, str); return v; } diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index faa7bd670d..4d9d172ccf 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1164,6 +1164,12 @@ class TestString < Test::Unit::TestCase 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 @@ -1803,6 +1809,13 @@ class TestString < Test::Unit::TestCase 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 @@ -1811,6 +1824,13 @@ class TestString < Test::Unit::TestCase 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 @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 170 +#define RUBY_PATCHLEVEL 171 #define RUBY_RELEASE_DATE "2012-03-30" #define RUBY_RELEASE_YEAR 2012 |