ruby-changes:47568
From: nobu <ko1@a...>
Date: Tue, 29 Aug 2017 19:49:43 +0900 (JST)
Subject: [ruby-changes:47568] nobu:r59684 (trunk): array.c: join encoding
nobu 2017-08-29 19:49:40 +0900 (Tue, 29 Aug 2017) New Revision: 59684 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59684 Log: array.c: join encoding * array.c (ary_join_1): copy the encoding of the converted string of the first element by to_str too, as an initial encoding. Modified files: trunk/array.c trunk/test/ruby/test_array.rb Index: array.c =================================================================== --- array.c (revision 59683) +++ array.c (revision 59684) @@ -1994,7 +1994,10 @@ ary_join_1(VALUE obj, VALUE ary, VALUE s https://github.com/ruby/ruby/blob/trunk/array.c#L1994 if (RB_TYPE_P(val, T_STRING)) { str_join: rb_str_buf_append(result, val); - *first = FALSE; + if (*first) { + rb_enc_copy(result, val); + *first = FALSE; + } } else if (RB_TYPE_P(val, T_ARRAY)) { obj = val; @@ -2025,10 +2028,6 @@ ary_join_1(VALUE obj, VALUE ary, VALUE s https://github.com/ruby/ruby/blob/trunk/array.c#L2028 goto ary_join; } val = rb_obj_as_string(val); - if (*first) { - rb_enc_copy(result, val); - *first = FALSE; - } goto str_join; } } Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 59683) +++ test/ruby/test_array.rb (revision 59684) @@ -1085,6 +1085,7 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L1085 assert_equal(Encoding::US_ASCII, [1, [u]].join.encoding) assert_equal(Encoding::UTF_8, [u, [e]].join.encoding) assert_equal(Encoding::UTF_8, [u, [1]].join.encoding) + assert_equal(Encoding::UTF_8, [Struct.new(:to_str).new(u)].join.encoding) bug5379 = '[ruby-core:39776]' assert_equal(Encoding::US_ASCII, [[], u, nil].join.encoding, bug5379) assert_equal(Encoding::UTF_8, [[], "\u3042", nil].join.encoding, bug5379) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/