aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-13 14:20:19 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-13 14:20:19 +0000
commit06454f65e69c1cf3efdb333434fd329273e116dd (patch)
tree21e78a3b75425af500e2b4547921f55bb1965726 /string.c
parente4200cfe2bb54f8c6d20d0f474490504fec81066 (diff)
downloadruby-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.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/string.c b/string.c
index 91c262eca9..1448ac21d7 100644
--- a/string.c
+++ b/string.c
@@ -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;
}