ruby-changes:46589
From: nobu <ko1@a...>
Date: Sat, 13 May 2017 23:20:25 +0900 (JST)
Subject: [ruby-changes:46589] nobu:r58705 (trunk): string.c: fix up r58703
nobu 2017-05-13 23:20:19 +0900 (Sat, 13 May 2017) New Revision: 58705 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58705 Log: 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. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 58704) +++ string.c (revision 58705) @@ -1008,8 +1008,12 @@ rb_external_str_new_with_enc(const char https://github.com/ruby/ruby/blob/trunk/string.c#L1008 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; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/