Project

General

Profile

Bug #11787 ยป 0001-object.c-rb_inspect-check-the-default-internal-encod.patch

shugo (Shugo Maeda), 12/08/2015 07:30 AM

View differences:

object.c
}
/*
* 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,
* the result must be ASCII only.
* 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 the default 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))
rb_raise(rb_eEncCompatError, "inspected result must be ASCII only if default external encoding is ASCII incompatible");
rb_raise(rb_eEncCompatError, "inspected result must be ASCII only if the default internal or 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 default external encoding");
if (rb_enc_get(str) != enc && !rb_enc_str_asciionly_p(str))
rb_raise(rb_eEncCompatError, "inspected result must be ASCII only or use the default internal or external encoding");
return str;
}
test/ruby/test_m17n.rb
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
    (1-1/1)