summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--string.c1
-rw-r--r--test/ruby/test_string.rb20
-rw-r--r--version.h2
4 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 318996b304..6faa75a730 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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].
diff --git a/string.c b/string.c
index d0f08a3f42..134d65b822 100644
--- a/string.c
+++ b/string.c
@@ -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
diff --git a/version.h b/version.h
index 81d4a88046..ffdf96fce5 100644
--- a/version.h
+++ b/version.h
@@ -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