From 0dec564748e6fe4fe4bee75b42ce816ee7b0b3e6 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 10 Dec 2015 18:57:08 +0000 Subject: * object.c (rb_inspect): dump inspected result with rb_str_escape() instead of raising Encoding::CompatibilityError. [Feature #11801] * string.c (rb_str_escape): added to dump given string like rb_str_inspect without quotes and always dump in US-ASCII like rb_str_dump. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index d339ff94b2..1f73cb401b 100644 --- a/object.c +++ b/object.c @@ -465,6 +465,7 @@ rb_any_to_s(VALUE obj) return str; } +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. @@ -478,11 +479,11 @@ rb_inspect(VALUE obj) 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 rb_str_escape(str); 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 default external encoding"); + return rb_str_escape(str); return str; } -- cgit v1.2.3