mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (rb_io_binmode): reset encoding conversion.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f560dfdd90
commit
0cda4bb3bf
3 changed files with 32 additions and 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):
|
||||
|
|
21
io.c
21
io.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue