summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--object.c13
-rw-r--r--test/ruby/test_m17n.rb13
3 files changed, 26 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 43074d25e2a..bf12b896313 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Dec 13 11:47:35 2015 Shugo Maeda <shugo@ruby-lang.org>
+
+ * object.c (rb_inspect): check the default internal encoding as
+ String#inspect do.
+ [ruby-dev:49415] [Bug #11787]
+
Sun Dec 13 11:38:12 2015 Akinori MUSHA <knu@iDaemons.org>
* lib/shellwords.rb: Turn on frozen-string-literal after fixing
diff --git a/object.c b/object.c
index 3111701c58a..99f58a8f6c0 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;
}
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 2e9e65b52f5..4efe18187b9 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -1648,4 +1648,17 @@ class TestM17N < Test::Unit::TestCase
assert_match(escape_plain, 0x5b.chr(::Encoding::UTF_8), bug10670)
assert_match(escape_plain, 0x5b.chr, bug10670)
end
+
+ def test_inspect_with_default_internal
+ bug11787 = '[ruby-dev:49415] [Bug #11787]'
+
+ orig_int = Encoding.default_internal
+ Encoding.default_internal = ::Encoding::EUC_JP
+ s = begin
+ [e("\xB4\xC1\xBB\xFA")].inspect
+ ensure
+ Encoding.default_internal = orig_int
+ end
+ assert_equal(e("[\"\xB4\xC1\xBB\xFA\"]"), s, bug11787)
+ end
end