diff --git a/io.c b/io.c index cef43bf..f12646f 100644 --- a/io.c +++ b/io.c @@ -2305,6 +2305,7 @@ io_read(int argc, VALUE *argv, VALUE io) if (len == 0) return str; READ_CHECK(fptr); + SET_BINARY_MODE_WITH_SEEK_CUR(fptr); n = io_fread(str, 0, fptr); if (n == 0) { if (fptr->fd < 0) return Qnil; diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 6f823c8..fd7b9fe 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -2222,4 +2222,15 @@ EOT end end end if /mswin|mingw/ =~ RUBY_PLATFORM + + def test_read_with_length + with_tmpdir { + str = "ab\r\nc" + generate_file('tmp', str) + s = open("tmp", "r") {|f| + # read with length should be binary mode + assert_equal(str, f.read(5)) + } + } + end if /mswin|mingw/ =~ RUBY_PLATFORM end