Project

General

Profile

Actions

Bug #6271

closed

textmode File#read on CRLF

Added by riskwa (riskwa anon) almost 12 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
ruby -v:
1.9.3p125 (2012-02-16) [i386-mingw32]
Backport:
[ruby-core:44189]

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


Files

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

Updated by nobu (Nobuyoshi Nakada) almost 12 years ago

  • Status changed from Open to Closed

Seems fixed already in the repository.

Updated by h.shirosaki (Hiroshi Shirosaki) almost 12 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) almost 12 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] (+read_eof.patch) : works fine

Updated by nobu (Nobuyoshi Nakada) almost 12 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
Actions #5

Updated by Anonymous almost 12 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0