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

string.c: fix up r58703

* string.c (rb_external_str_new_with_enc): fix the case of
  conversion failure.  when conversion failed for some reason,
  just ignores the default internal encoding and returns in the
  given encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-05-13 14:20:19 +00:00
parent eafeb506cd
commit a3960d0a60

View file

@ -1008,8 +1008,12 @@ rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *eenc)
if (!ienc || eenc == ienc) { if (!ienc || eenc == ienc) {
return rb_tainted_str_new_with_enc(ptr, len, eenc); return rb_tainted_str_new_with_enc(ptr, len, eenc);
} }
str = rb_tainted_str_new_with_enc(NULL, len, ienc); str = rb_tainted_str_new_with_enc(NULL, 0, ienc);
rb_str_cat_conv_enc_opts(str, 0, ptr, len, eenc, 0, Qnil); if (NIL_P(rb_str_cat_conv_enc_opts(str, 0, ptr, len, eenc, 0, Qnil))) {
STR_SET_LEN(str, 0);
rb_enc_associate(str, eenc);
rb_str_cat(str, ptr, len);
}
return str; return str;
} }