From c69ef4127734c583770b13411e49cbec7af817cd Mon Sep 17 00:00:00 2001 From: shugo Date: Sun, 13 Dec 2015 02:48:34 +0000 Subject: * object.c (rb_inspect): check the default internal encoding as String#inspect do. [ruby-dev:49415] [Bug #11787] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 3111701c58..99f58a8f6c 100644 --- a/object.c +++ b/object.c @@ -467,22 +467,23 @@ rb_any_to_s(VALUE obj) VALUE rb_str_escape(VALUE str); /* - * If the default external encoding is ASCII compatible, the encoding of - * the inspected result must be compatible with it. - * If the default external encoding is ASCII incompatible, + * If the default internal or external encoding is ASCII compatible, + * the encoding of the inspected result must be compatible with it. + * If the default internal or external encoding is ASCII incompatible, * the result must be ASCII only. */ VALUE rb_inspect(VALUE obj) { VALUE str = rb_obj_as_string(rb_funcallv(obj, id_inspect, 0, 0)); - rb_encoding *ext = rb_default_external_encoding(); - if (!rb_enc_asciicompat(ext)) { + rb_encoding *enc = rb_default_internal_encoding(); + if (enc == NULL) enc = rb_default_external_encoding(); + if (!rb_enc_asciicompat(enc)) { if (!rb_enc_str_asciionly_p(str)) return rb_str_escape(str); return str; } - if (rb_enc_get(str) != ext && !rb_enc_str_asciionly_p(str)) + if (rb_enc_get(str) != enc && !rb_enc_str_asciionly_p(str)) return rb_str_escape(str); return str; } -- cgit v1.2.3