📝

[Bug #21634] Windows 環境で read(1) + IO#eof? の挙動がおかしいというバグ報告

に公開

[Bug #21634] Combining read(1) with eof? causes dropout of results unexpectedly on Windows.

  • EOF(\x1A) が含まれているファイルを read(1) + IO#eof? で読み込んだときに Windows で意図しない挙動になるというバグ報告
irb(main):001> IO.binwrite("txt", "abcd\x1A")
=> 5
irb(main):002> open("txt", "r") { p _1.read(1) until _1.eof? }; # こっちは期待する挙動
"a"
"b"
"c"
"d"
"\x1A"
irb(main):003> open("txt", "rt") { p _1.read(1) until _1.eof? }; # 意図しない読み込みになる
"b"
"d"
irb(main):004>
  • open するときに "r" であれば問題ないんですが "rt" だと意図しない読み込みになるみたい
  • これは "rt" のときに O_BINARY で読み込まれるが O_TEXT で開こうとしているのが問題みたい?
  • まだ対応中みたい
GitHubで編集を提案

Discussion