ruby-changes:35223
From: nobu <ko1@a...>
Date: Thu, 28 Aug 2014 14:55:43 +0900 (JST)
Subject: [ruby-changes:35223] nobu:r47305 (trunk): io.c: preserve encodings
nobu 2014-08-28 14:55:22 +0900 (Thu, 28 Aug 2014) New Revision: 47305 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47305 Log: io.c: preserve encodings * io.c (rb_io_extract_encoding_option): preserve encodings in warning messages. Modified files: trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: io.c =================================================================== --- io.c (revision 47304) +++ io.c (revision 47305) @@ -5194,9 +5194,9 @@ rb_io_extract_encoding_option(VALUE opt, https://github.com/ruby/ruby/blob/trunk/io.c#L5194 if ((extenc != Qundef || intenc != Qundef) && !NIL_P(encoding)) { if (!NIL_P(ruby_verbose)) { int idx = rb_to_encoding_index(encoding); - rb_warn("Ignoring encoding parameter '%s': %s_encoding is used", - idx < 0 ? StringValueCStr(encoding) : rb_enc_name(rb_enc_from_index(idx)), - extenc == Qundef ? "internal" : "external"); + if (idx >= 0) encoding = rb_enc_from_encoding(rb_enc_from_index(idx)); + rb_warn("Ignoring encoding parameter '%"PRIsVALUE"': %s_encoding is used", + encoding, extenc == Qundef ? "internal" : "external"); } encoding = Qnil; } Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 47304) +++ test/ruby/test_io_m17n.rb (revision 47305) @@ -312,6 +312,17 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L312 } end + def test_ignored_encoding_option + enc = "\u{30a8 30f3 30b3 30fc 30c7 30a3 30f3 30b0}" + pattern = /#{enc}/ + assert_warning(pattern) { + open(IO::NULL, external_encoding: "us-ascii", encoding: enc) + } + assert_warning(pattern) { + open(IO::NULL, internal_encoding: "us-ascii", encoding: enc) + } + end + def test_io_new_enc with_tmpdir { generate_file("tmp", "\xa1") -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/