1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-08-29 10:49:40 +00:00
parent 9d99093169
commit cb70a92ece
2 changed files with 5 additions and 5 deletions

View file

@ -1994,7 +1994,10 @@ ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result, int *first)
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 sep, long i, VALUE result, int *first)
goto ary_join;
}
val = rb_obj_as_string(val);
if (*first) {
rb_enc_copy(result, val);
*first = FALSE;
}
goto str_join;
}
}

View file

@ -1085,6 +1085,7 @@ class TestArray < Test::Unit::TestCase
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)