diff options
-rw-r--r-- | string.c | 1 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 3 |
2 files changed, 4 insertions, 0 deletions
@@ -1551,6 +1551,7 @@ rb_str_init(int argc, VALUE *argv, VALUE str) if (n == 1) { memcpy(RSTRING(str)->as.heap.ptr, RSTRING_PTR(orig), len); rb_enc_cr_str_exact_copy(str, orig); + FL_UNSET(str, STR_SHARED|STR_NOFREE); } FL_SET(str, STR_NOEMBED); RSTRING(str)->as.heap.aux.capa = capa; diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index c3fd2b7d94..c83ea2a8b9 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -68,6 +68,9 @@ class TestString < Test::Unit::TestCase assert_raise(RuntimeError){ str.__send__(:initialize, encoding: 'euc-jp') } assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', encoding: 'euc-jp') } assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') } + + str = S("x"*40).freeze.dup # shared string + assert_equal("a", str.send(:initialize, "a", capacity: 1000).dup) end def test_initialize_nonstring |