mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (extract_binmode): raise an exception if binmode/textmode
is specified with both vmode and opthash. [ruby-core:42199] [Bug #5918] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e7d83904cb
commit
aa5b65b2ed
3 changed files with 43 additions and 4 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Mon Jan 23 16:42:28 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Mon Jan 23 16:35:27 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (rb_io_extract_modeenc): set ASCII-8BIT if binmode is specified
|
* io.c (rb_io_extract_modeenc): set ASCII-8BIT if binmode is specified
|
||||||
|
|
12
io.c
12
io.c
|
@ -4786,11 +4786,19 @@ extract_binmode(VALUE opthash, int *fmode)
|
||||||
if (!NIL_P(opthash)) {
|
if (!NIL_P(opthash)) {
|
||||||
VALUE v;
|
VALUE v;
|
||||||
v = rb_hash_aref(opthash, sym_textmode);
|
v = rb_hash_aref(opthash, sym_textmode);
|
||||||
if (!NIL_P(v) && RTEST(v))
|
if (!NIL_P(v)) {
|
||||||
|
if (*fmode & FMODE_TEXTMODE)
|
||||||
|
rb_raise(rb_eArgError, "textmode specified twice");
|
||||||
|
if (RTEST(v))
|
||||||
*fmode |= FMODE_TEXTMODE;
|
*fmode |= FMODE_TEXTMODE;
|
||||||
|
}
|
||||||
v = rb_hash_aref(opthash, sym_binmode);
|
v = rb_hash_aref(opthash, sym_binmode);
|
||||||
if (!NIL_P(v) && RTEST(v))
|
if (!NIL_P(v)) {
|
||||||
|
if (*fmode & FMODE_BINMODE)
|
||||||
|
rb_raise(rb_eArgError, "binmode specified twice");
|
||||||
|
if (RTEST(v))
|
||||||
*fmode |= FMODE_BINMODE;
|
*fmode |= FMODE_BINMODE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((*fmode & FMODE_BINMODE) && (*fmode & FMODE_TEXTMODE))
|
if ((*fmode & FMODE_BINMODE) && (*fmode & FMODE_TEXTMODE))
|
||||||
rb_raise(rb_eArgError, "both textmode and binmode specified");
|
rb_raise(rb_eArgError, "both textmode and binmode specified");
|
||||||
|
|
|
@ -1047,6 +1047,29 @@ EOT
|
||||||
f.set_encoding("iso-2022-jp")
|
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
|
end
|
||||||
|
|
||||||
def test_write_conversion_fixenc
|
def test_write_conversion_fixenc
|
||||||
|
@ -1344,6 +1367,8 @@ EOT
|
||||||
|
|
||||||
def test_both_textmode_binmode
|
def test_both_textmode_binmode
|
||||||
assert_raise(ArgumentError) { open("not-exist", "r", :textmode=>true, :binmode=>true) }
|
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
|
end
|
||||||
|
|
||||||
def test_textmode_decode_universal_newline_read
|
def test_textmode_decode_universal_newline_read
|
||||||
|
|
Loading…
Add table
Reference in a new issue