From: "h.shirosaki (Hiroshi Shirosaki)" <h.shirosaki@...>
Date: 2012-05-07T21:20:01+09:00
Subject: [ruby-core:44921] [ruby-trunk - Bug #6401] Windows bug with File.pos


Issue #6401 has been updated by h.shirosaki (Hiroshi Shirosaki).

File fix_pos_with_readline.patch added

I confirmed the issue. Thanks for your test case.
If the end of reading buffer is CR, io_unread() needs to unread one more byte for CR.
I created a patch and a simplified test case for that.
----------------------------------------
Bug #6401: Windows bug with File.pos
https://bugs.ruby-lang.org/issues/6401#change-26510

Author: jmthomas (Jason Thomas)
Status: Assigned
Priority: Normal
Assignee: h.shirosaki (Hiroshi Shirosaki)
Category: core
Target version: 1.9.3
ruby -v: ruby 1.9.3p194 (2012-04-20) [i386-mingw32]


On Windows since Ruby 1.9.3p125 there have been issues with File.pos and File.readline. Ruby 1.9.3p0 does not have this issue. I have created the following test:

  def test_pos_with_readline
    t = make_tempfile
    random = Random.new(1234)
    open(t.path, "w") do |f|
      500.times do
        f.puts "X"*random.rand(80)
      end
    end
    i = 0
    lines = open(t.path,'r').read.split("\n")
    open(t.path, "r") do |f|
      lines.length.times do
        f.pos
        assert_equal lines[i], f.readline.chomp
        i += 1
      end
    end
  end

If you comment out the f.pos line this test case will pass. I originally submitted issue #6179 but the fixes applied there made things better but did not complete solve the problem. I apologize for the test case but it requires many lines with newlines to reproduce.


-- 
http://bugs.ruby-lang.org/