Project

General

Profile

Bug #6271

textmode File#read on CRLF

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

Status:
Closed
Priority:
Normal
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

Associated revisions

Revision 2f7290d4
Added by shirosaki over 7 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'.
    [ruby-core:44189][Bug #6271]

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 35296
Added by shirosaki over 7 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'.
    [ruby-core:44189][Bug #6271]

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

Revision 35296
Added by shirosaki over 7 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'.
    [ruby-core:44189][Bug #6271]

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

Revision 35296
Added by shirosaki over 7 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'.
    [ruby-core:44189][Bug #6271]

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

Revision 35296
Added by shirosaki over 7 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'.
    [ruby-core:44189][Bug #6271]

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

Revision 35296
Added by shirosaki over 7 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'.
    [ruby-core:44189][Bug #6271]

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

Revision 35296
Added by shirosaki over 7 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'.
    [ruby-core:44189][Bug #6271]

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

Revision 72012911
Added by naruse (Yui NARUSE) over 7 years ago

merge revision(s) 35296: [Backport #6295]

    * 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Status changed from Open to Closed

Seems fixed already in the repository.

Updated by h.shirosaki (Hiroshi Shirosaki) over 7 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 7 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 7 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
#5

Updated by Anonymous over 7 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