diff --git a/ChangeLog b/ChangeLog index 0546c1c690..008905a89f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Jan 8 07:56:11 2008 Tanaka Akira + + * string.c (rb_str_buf_append): fix append itself. + Tue Jan 8 01:13:50 2008 Tanaka Akira * string.c (STR_ENC_GET): defined. same as rb_enc_get without diff --git a/string.c b/string.c index 95c4e0c440..189cc1b751 100644 --- a/string.c +++ b/string.c @@ -1166,7 +1166,13 @@ rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *ptr_enc) VALUE rb_str_buf_append(VALUE str, VALUE str2) { - int str2_cr = ENC_CODERANGE(str2); + int str2_cr; + + if (str == str2) { + str2 = rb_str_dup(str2); + } + + str2_cr = ENC_CODERANGE(str2); rb_enc_cr_str_buf_cat(str, RSTRING_PTR(str2), RSTRING_LEN(str2), ENCODING_GET(str2), str2_cr, &str2_cr); diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 524ab47051..647c520707 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -170,6 +170,12 @@ class TestString < Test::Unit::TestCase def test_LSHIFT # '<<' assert_equal(S("world!"), S("world") << 33) assert_equal(S("world!"), S("world") << S('!')) + + s = "a" + 10.times {|i| + s << s + assert_equal("a" * (2<