diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | io.c | 21 | ||||
-rw-r--r-- | test/ruby/test_io_m17n.rb | 13 |
3 files changed, 32 insertions, 6 deletions
@@ -1,3 +1,7 @@ +Fri Oct 17 00:24:15 2008 Tanaka Akira <akr@fsij.org> + + * io.c (rb_io_binmode): reset encoding conversion. + Fri Oct 17 00:16:08 2008 Yusuke Endoh <mame@tsg.ne.jp> * io.c (rb_getc, rb_io_fread, rb_io_fwrite, rb_read_pending): @@ -3503,13 +3503,24 @@ rb_io_binmode(VALUE io) rb_io_t *fptr; GetOpenFile(io, fptr); - if (fptr->readconv) - rb_econv_binmode(fptr->readconv); - if (fptr->writeconv) - rb_econv_binmode(fptr->writeconv); + + if (fptr->readconv) { + rb_econv_close(fptr->readconv); + fptr->readconv = NULL; + } + if (fptr->writeconv) { + rb_econv_close(fptr->writeconv); + fptr->writeconv = NULL; + } fptr->mode |= FMODE_BINMODE; fptr->mode &= ~FMODE_TEXTMODE; - fptr->writeconv_pre_ecflags &= ~(ECONV_UNIVERSAL_NEWLINE_DECORATOR|ECONV_CRLF_NEWLINE_DECORATOR|ECONV_CR_NEWLINE_DECORATOR); + + fptr->encs.enc = rb_ascii8bit_encoding(); + fptr->encs.enc2 = NULL; + fptr->encs.ecflags = 0; + fptr->encs.ecopts = Qnil; + clear_codeconv(fptr); + return io; } diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index bff2846608..eeec26d61e 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -678,7 +678,6 @@ EOT def test_getc_invalid3 with_pipe("utf-16le:euc-jp") {|r, w| - w.binmode before1 = "\x42\x30".force_encoding("utf-16le") before2 = "\x44\x30".force_encoding("utf-16le") invalid = "\x00\xd8".force_encoding("utf-16le") @@ -1539,6 +1538,18 @@ EOT } end + def test_binmode3 + with_tmpdir { + src = "\u3042\r\n" + generate_file("t.txt", src) + srcbin = src.dup.force_encoding("ascii-8bit") + open("t.txt", "rt:utf-8:euc-jp") {|f| + f.binmode + assert_str_equal(srcbin, f.read) + } + } + end + def test_invalid_r with_tmpdir { generate_file("t.txt", "a\x80b") |