From: Heesob Park Date: 2012-01-13T15:11:03+09:00 Subject: [ruby-core:42106] [ruby-trunk - Bug #5848] Array#inspect having an element with non-ASCII compatible #inspect result Issue #5848 has been updated by Heesob Park. Here is a patch for this issue. But I suspect it may cause another issue. diff --git a/array.c b/array.c.new index e58ac0b..bdad94d 100644 --- a/array.c +++ b/array.c.new @@ -1792,19 +1792,24 @@ inspect_ary(VALUE ary, VALUE dummy, int recur) int tainted = OBJ_TAINTED(ary); int untrust = OBJ_UNTRUSTED(ary); long i; - VALUE s, str; + VALUE s, str, temp; if (recur) return rb_usascii_str_new_cstr("[...]"); str = rb_str_buf_new2("["); + temp = rb_str_buf_new2(", "); for (i=0; i 0) rb_str_buf_cat2(str, ", "); - else rb_enc_copy(str, s); + if (i > 0) { + temp = rb_str_conv_enc(temp,rb_enc_get(temp),rb_enc_get(str)); + rb_str_buf_append(str, temp); + } else + str = rb_str_conv_enc(str,rb_enc_get(str),rb_enc_get(s)); rb_str_buf_append(str, s); } - rb_str_buf_cat2(str, "]"); + temp = rb_str_conv_enc(rb_str_buf_new2("]"),rb_usascii_encoding(),rb_enc_get(str)); + rb_str_buf_append(str, temp); if (tainted) OBJ_TAINT(str); if (untrust) OBJ_UNTRUST(str); return str; ---------------------------------------- Bug #5848: Array#inspect having an element with non-ASCII compatible #inspect result https://bugs.ruby-lang.org/issues/5848 Author: John Firebaugh Status: Assigned Priority: Normal Assignee: Yui NARUSE Category: Target version: ruby -v: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0] Is this a bug? >> class O >> def inspect >> "foo".encode!(Encoding::UTF_16BE) >> end >> end => nil >> [O.new].inspect => "\u5B00\u6600\u6F00\u6F5D" -- http://bugs.ruby-lang.org/