summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-13 02:48:34 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-13 02:48:34 +0000
commit2854a7f121861b7508809815532d6827b8bb9929 (patch)
treee3a43165067b727ac766bf097860e3a4e1976468
parentfdfb8804c0d2665e8b82f211fe327b887f2d0b01 (diff)
* 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
-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 43074d2..bf12b89 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 3111701..99f58a8 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 2e9e65b..4efe181 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