Preserve the string content at self-copying

* string.c (rb_str_init): preserve the embedded content when
  self-copying with a capacity.  [Bug #15937]
This commit is contained in:
Nobuyoshi Nakada 2019-06-19 09:44:26 +09:00
parent d009e321a0
commit 28678997e4
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 13 additions and 1 deletions

View file

@ -68,6 +68,15 @@ class TestString < Test::Unit::TestCase
assert_raise(FrozenError){ str.__send__(:initialize, encoding: 'euc-jp') }
assert_raise(FrozenError){ str.__send__(:initialize, 'abc', encoding: 'euc-jp') }
assert_raise(FrozenError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') }
str = S("")
assert_equal("mystring", str.__send__(:initialize, "mystring"))
str = S("mystring")
assert_equal("mystring", str.__send__(:initialize, str))
str = S("")
assert_equal("mystring", str.__send__(:initialize, "mystring", capacity: 1000))
str = S("mystring")
assert_equal("mystring", str.__send__(:initialize, str, capacity: 1000))
end
def test_initialize_nonstring