diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-13 14:20:19 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-13 14:20:19 +0000 |
commit | 06454f65e69c1cf3efdb333434fd329273e116dd (patch) | |
tree | 21e78a3b75425af500e2b4547921f55bb1965726 /string.c | |
parent | e4200cfe2bb54f8c6d20d0f474490504fec81066 (diff) | |
download | ruby-06454f65e69c1cf3efdb333434fd329273e116dd.tar.gz |
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
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -1008,8 +1008,12 @@ rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *eenc) if (!ienc || eenc == ienc) { return rb_tainted_str_new_with_enc(ptr, len, eenc); } - str = rb_tainted_str_new_with_enc(NULL, len, ienc); - rb_str_cat_conv_enc_opts(str, 0, ptr, len, eenc, 0, Qnil); + str = rb_tainted_str_new_with_enc(NULL, 0, ienc); + 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; } |