From: "YO4 (Yoshinao Muramatsu) via ruby-dev" <ruby-dev@ml.ruby-lang.org>
To: ruby-dev@ml.ruby-lang.org
Cc: "YO4 (Yoshinao Muramatsu)" <noreply@ruby-lang.org>
Subject: [ruby-dev:52133] [Ruby master Feature#11177] DATAでEOF文字以降が読めない
Date: Fri, 22 Nov 2024 14:15:10 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-110732.20241122141509.18@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-11177.20150524055355.18@ruby-lang.org>
Issue #11177 has been updated by YO4 (Yoshinao Muramatsu).
rubyの-xオプション付与でソースファイルをバイナリオープンさせることでも```\x1A```以降の読み込みが可能でした。
こちらは ruby 3.3またはそれ以前でも可能のようです。
```
>less -F data.rb
#!ruby
DATA.pos # posなしだと [] しか得られない
p IO.open(DATA.fileno, "rt") {|f| f.readlines }
__END__
textpart1
textpart1^Z
binpart1
binpart2
>ruby -x data.rb
["textpart1\n", "textpart1\u001A\n", "binpart1\n", "binpart2\n"]
```
同様の動作を仕込むことで EOF以降も DATAでアクセス可能にできそうですが、DATA.class が Fileでなく IOになっちゃいますね…
----------------------------------------
Feature #11177: DATAでEOF文字以降が読めない
https://bugs.ruby-lang.org/issues/11177#change-110732
* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
遠藤です。
Windows で `__END__` 以降に EOF 文字 (`\x1A`) があったとき、それより先が読めないのは仕様でしょうか。
gen.rb:
puts "p DATA.read"
puts "__END__"
puts "foo\x1Abar"
以下のように実行すると再現します。
> ruby gen.rb > t.rb
> ruby t.rb
"foo"
`DATA.binmode.read` などとしてみても同じです。
もちろん、Linux では先まで読めます。Windows でも、ソースコードをパイプで流し込んだ場合はなぜか読めます。
> ruby < t.rb
"foo\x1Abar\n"
さらに、EOF 以降に文字がいっぱいあった場合、EOF 以降の一部の文字が抜け落ちるような挙動になるようです。
gen2.rb:
puts "p DATA.read"
puts "__END__"
puts "foo\x1A" + "X" * 8192 + "Z"
> ruby gen2.rb > t.rb
> ruby t.rb
"fooXXXXXXXXXXXXXXXXXXXXXXXXXXXZ\r\n"
バッファリングのバグっぽい挙動ですが、バグでしょうか。
--
Yusuke Endoh <mame@ruby-lang.org>
--
https://bugs.ruby-lang.org/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
prev parent reply other threads:[~2024-11-22 14:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-11177.20150524055355.18@ruby-lang.org>
2024-11-21 15:02 ` [ruby-dev:52132] " YO4 (Yoshinao Muramatsu) via ruby-dev
2024-11-22 14:15 ` YO4 (Yoshinao Muramatsu) via ruby-dev [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-110732.20241122141509.18@ruby-lang.org \
--to=ruby-dev@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).