ruby-changes:28558
From: naruse <ko1@a...>
Date: Wed, 8 May 2013 17:47:38 +0900 (JST)
Subject: [ruby-changes:28558] naruse:r40610 (trunk): * io.c (rb_io_ext_int_to_encs): ignore internal encoding if external
naruse 2013-05-08 17:47:26 +0900 (Wed, 08 May 2013) New Revision: 40610 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40610 Log: * io.c (rb_io_ext_int_to_encs): ignore internal encoding if external encoding is ASCII-8BIT. [Bug #8342] Modified files: trunk/ChangeLog trunk/NEWS trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 40609) +++ ChangeLog (revision 40610) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed May 8 17:43:55 2013 NARUSE, Yui <naruse@r...> + + * io.c (rb_io_ext_int_to_encs): ignore internal encoding if external + encoding is ASCII-8BIT. [Bug #8342] + Wed May 8 13:49:38 2013 NARUSE, Yui <naruse@r...> * ext/json/generator/generator.c (isArrayOrObject): cast char to Index: io.c =================================================================== --- io.c (revision 40609) +++ io.c (revision 40610) @@ -4868,9 +4868,13 @@ rb_io_ext_int_to_encs(rb_encoding *ext, https://github.com/ruby/ruby/blob/trunk/io.c#L4868 ext = rb_default_external_encoding(); default_ext = 1; } - if (intern == NULL && ext != rb_ascii8bit_encoding()) - /* If external is ASCII-8BIT, no default transcoding */ + if (ext == rb_ascii8bit_encoding()) { + /* If external is ASCII-8BIT, no transcoding */ + intern = NULL; + } + else if (intern == NULL) { intern = rb_default_internal_encoding(); + } if (intern == NULL || intern == (rb_encoding *)Qnil || (!(fmode & FMODE_SETENC_BY_BOM) && (intern == ext))) { /* No internal encoding => use external + no transcoding */ Index: NEWS =================================================================== --- NEWS (revision 40609) +++ NEWS (revision 40610) @@ -39,6 +39,10 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L39 === Core classes compatibility issues (excluding feature bug fixes) +* IO + * incompatible changes: + * open ignore internal encoding if external encoding is ASCII-8BIT. + * Module#ancestors The ancestors of a singleton class now include singleton classes, Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 40609) +++ test/ruby/test_io_m17n.rb (revision 40610) @@ -105,6 +105,42 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L105 } end + def test_open_r_ascii8bit + with_tmpdir { + generate_file('tmp', "") + EnvUtil.with_default_external(Encoding::ASCII_8BIT) do + EnvUtil.with_default_internal(Encoding::UTF_8) do + open("tmp", "r") {|f| + assert_equal(Encoding::ASCII_8BIT, f.external_encoding) + assert_equal(nil, f.internal_encoding) + } + open("tmp", "r:ascii-8bit") {|f| + assert_equal(Encoding::ASCII_8BIT, f.external_encoding) + assert_equal(nil, f.internal_encoding) + } + open("tmp", "r:ascii-8bit:utf-16") {|f| + assert_equal(Encoding::ASCII_8BIT, f.external_encoding) + assert_equal(nil, f.internal_encoding) + } + end + EnvUtil.with_default_internal(nil) do + open("tmp", "r") {|f| + assert_equal(Encoding::ASCII_8BIT, f.external_encoding) + assert_equal(nil, f.internal_encoding) + } + open("tmp", "r:ascii-8bit") {|f| + assert_equal(Encoding::ASCII_8BIT, f.external_encoding) + assert_equal(nil, f.internal_encoding) + } + open("tmp", "r:ascii-8bit:utf-16") {|f| + assert_equal(Encoding::ASCII_8BIT, f.external_encoding) + assert_equal(nil, f.internal_encoding) + } + end + end + } + end + def test_open_r_enc_in_opt with_tmpdir { generate_file('tmp', "") -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/