Bug #6271

textmode File#read on CRLF

Added by riskwa anon almost 3 years ago. Updated almost 3 years ago.

[ruby-core:44189]
Status:Closed
Priority:Normal
Assignee:Hiroshi Shirosaki
ruby -v:1.9.3p125 (2012-02-16) [i386-mingw32] Backport:

Description

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.

File.open(FILE, "r") do |f|
until f.eof?
p f.read(1)
end
end

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

Associated revisions

Revision 35296
Added by shirosaki almost 3 years ago

  • 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'.
    [Bug #6271]

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

Revision 35296
Added by shirosaki almost 3 years ago

  • 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'.
    [Bug #6271]

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

History

#1 Updated by Nobuyoshi Nakada almost 3 years ago

  • Status changed from Open to Closed

Seems fixed already in the repository.

#2 Updated by Hiroshi Shirosaki almost 3 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.

#3 Updated by riskwa anon almost 3 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

#4 Updated by Nobuyoshi Nakada almost 3 years ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to Hiroshi Shirosaki
  • Target version changed from 1.9.3 to 2.0.0

#5 Updated by Anonymous almost 3 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'.
    [Bug #6271]

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

Also available in: Atom PDF