ruby-changes:22310
From: naruse <ko1@a...>
Date: Mon, 23 Jan 2012 16:59:57 +0900 (JST)
Subject: [ruby-changes:22310] naruse:r34359 (trunk): * io.c (extract_binmode): raise an exception if binmode/textmode
naruse 2012-01-23 16:56:25 +0900 (Mon, 23 Jan 2012) New Revision: 34359 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34359 Log: * io.c (extract_binmode): raise an exception if binmode/textmode is specified with both vmode and opthash. [ruby-core:42199] [Bug #5918] Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34358) +++ ChangeLog (revision 34359) @@ -1,3 +1,9 @@ +Mon Jan 23 16:42:28 2012 NARUSE, Yui <naruse@r...> + + * io.c (extract_binmode): raise an exception if binmode/textmode + is specified with both vmode and opthash. + [ruby-core:42199] [Bug #5918] + Mon Jan 23 16:35:27 2012 NARUSE, Yui <naruse@r...> * io.c (rb_io_extract_modeenc): set ASCII-8BIT if binmode is specified Index: io.c =================================================================== --- io.c (revision 34358) +++ io.c (revision 34359) @@ -4786,11 +4786,19 @@ if (!NIL_P(opthash)) { VALUE v; v = rb_hash_aref(opthash, sym_textmode); - if (!NIL_P(v) && RTEST(v)) - *fmode |= FMODE_TEXTMODE; + if (!NIL_P(v)) { + if (*fmode & FMODE_TEXTMODE) + rb_raise(rb_eArgError, "textmode specified twice"); + if (RTEST(v)) + *fmode |= FMODE_TEXTMODE; + } v = rb_hash_aref(opthash, sym_binmode); - if (!NIL_P(v) && RTEST(v)) - *fmode |= FMODE_BINMODE; + if (!NIL_P(v)) { + if (*fmode & FMODE_BINMODE) + rb_raise(rb_eArgError, "binmode specified twice"); + if (RTEST(v)) + *fmode |= FMODE_BINMODE; + } if ((*fmode & FMODE_BINMODE) && (*fmode & FMODE_TEXTMODE)) rb_raise(rb_eArgError, "both textmode and binmode specified"); Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 34358) +++ test/ruby/test_io_m17n.rb (revision 34359) @@ -1047,8 +1047,31 @@ f.set_encoding("iso-2022-jp") } } + assert_raise(ArgumentError) { + open(__FILE__, "rb", binmode: true) {|f| + f.set_encoding("iso-2022-jp") + } + } + assert_raise(ArgumentError) { + open(__FILE__, "rb", binmode: false) {|f| + f.set_encoding("iso-2022-jp") + } + } end + def test_textmode_twice + assert_raise(ArgumentError) { + open(__FILE__, "rt", textmode: true) {|f| + f.set_encoding("iso-2022-jp") + } + } + assert_raise(ArgumentError) { + open(__FILE__, "rt", textmode: false) {|f| + f.set_encoding("iso-2022-jp") + } + } + end + def test_write_conversion_fixenc pipe(proc do |w| w.set_encoding("iso-2022-jp:utf-8") @@ -1344,6 +1367,8 @@ def test_both_textmode_binmode assert_raise(ArgumentError) { open("not-exist", "r", :textmode=>true, :binmode=>true) } + assert_raise(ArgumentError) { open("not-exist", "rt", :binmode=>true) } + assert_raise(ArgumentError) { open("not-exist", "rb", :textmode=>true) } end def test_textmode_decode_universal_newline_read -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/