summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-15 07:28:50 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-15 07:28:50 +0000
commitef18be23664d105954a2685a28e5deb868fa6a8e (patch)
tree8d8c33b2e6d179cc2b061a25a84fe56cf5497f2e /object.c
parent4c5171bb17198984de8424d3e1b5f2652f3256a9 (diff)
* object.c (rb_inspect): raise the result is not compatible with
the default external encoding. [ruby-core:42095] [Bug #5848] If the default external encoding is ASCII compatible, the encoding of inspected result must be compatible with it. If the default external encoding is ASCII incomapatible, the result must be ASCII only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/object.c b/object.c
index 09b3999231..e3302d153e 100644
--- a/object.c
+++ b/object.c
@@ -368,12 +368,25 @@ rb_any_to_s(VALUE obj)
return str;
}
+/*
+ * If the default external encoding is ASCII compatible, the encoding of
+ * inspected result must be compatible with it.
+ * If the default external encoding is ASCII incomapatible,
+ * the result must be ASCII only.
+ */
VALUE
rb_inspect(VALUE obj)
{
- VALUE s = rb_obj_as_string(rb_funcall(obj, id_inspect, 0, 0));
- rb_enc_check(rb_enc_default_external(), s);
- return s;
+ VALUE str = rb_obj_as_string(rb_funcall(obj, id_inspect, 0, 0));
+ rb_encoding *ext = rb_default_external_encoding();
+ if (!rb_enc_asciicompat(ext)) {
+ if (!rb_enc_str_asciionly_p(str))
+ rb_raise(rb_eEncCompatError, "inspected result must be ASCII only if default external encoding is ASCII incompatible");
+ return str;
+ }
+ if (rb_enc_get(str) != ext && !rb_enc_str_asciionly_p(str))
+ rb_raise(rb_eEncCompatError, "inspected result must be ASCII only or use the same encoding with default external");
+ return str;
}
static int