Bug #6271

textmode File#read on CRLF

Added by riskwa (riskwa anon) over 8 years ago. Updated over 8 years ago.

Target version:
ruby -v:
1.9.3p125 (2012-02-16) [i386-mingw32]


I'm not sure this is bug,
when "File#read(X)" for textmode finishes inside of CRLF, stream keeps CR unread against my intuition.
The following code prints "\r" forever for CRLF., "r") do |f|
until f.eof?


read_eof.patch (1.1 KB) read_eof.patch h.shirosaki (Hiroshi Shirosaki), 04/08/2012 10:34 PM

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Status changed from Open to Closed

Seems fixed already in the repository.

Updated by h.shirosaki (Hiroshi Shirosaki) over 8 years ago

I think that is not fixed yet.
io_unread() doesn't work properly in that case.
An idea is not using read into buffer in rb_io_eof() only in that case. Attached the patch.

Updated by riskwa (riskwa anon) over 8 years ago

I tested the code above in some environments.
(a) ruby 1.9.3p125 (2012-02-16 revision 34643) [i386-cygwin] : works fine
(b) ruby 2.0.0dev (2012-04-08 trunk 35259) [i386-cygwin] : works fine
(c) ruby 1.9.3p125 (2012-02-16) [i386-mingw32] : NG
(d) ruby 2.0.0dev (2012-04-08) [i386-mingw32] : NG
(e) ruby 2.0.0dev (2012-04-08) i386-mingw32 : works fine

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to h.shirosaki (Hiroshi Shirosaki)
  • Target version changed from 1.9.3 to 2.0.0

Updated by Anonymous over 8 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35296.
riskwa, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

  • io.c (rb_io_eof): use eof() instead of io_fillbuf(). It's because
    io_unread() doesn't work properly when reading CRLF with read(length)
    and mode 'r'.
    [ruby-core:44189][Bug #6271]

  • test/ruby/test_io_m17n.rb (TestIO_M17N#test_read_crlf_and_eof):
    test for above.

Also available in: Atom PDF