Project

General

Profile

Actions

Bug #21687

open

IO#pos goes wrong after EOF character(ctrl-z) met.

Bug #21687: IO#pos goes wrong after EOF character(ctrl-z) met.

Added by YO4 (Yoshinao Muramatsu) about 17 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x64-mingw-ucrt]
[ruby-core:123806]

Description

In Windows environment, when opening a file with the "r", encountering an EOF character (Ctrl-Z, "\x1A") during reading causes the IO to report END-OF-FILE.

require 'tempfile'

Tempfile.open do |f|
  str = "0123456789\x1A"
  f.write(str + "x"*(1024_0 - str.bytesize))
  f.rewind
  p f.readline.size # => 10
  p f.pos           # => 8191, shuld be 10 but equals rbuf size
end

When the file reaches its end, the file position moves to the position after the last character.
Therefore, when encountering the EOF character, the file position is expected to move to the position of the EOF character.

This is somewhat unrelated, but I understand that self.seek(0, File::SEEK_END) not positioning at the EOF character is a known limitation.

No data to display

Actions

Also available in: PDF Atom