mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
fdfb8804c0
commit
2854a7f121
3 changed files with 26 additions and 6 deletions
|
@ -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
|
||||
|
|
13
object.c
13
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue