[ruby-core:123182] [Ruby Bug#21562] IO#each_codepoint raises using with IO#ungetc
From:
"YO4 (Yoshinao Muramatsu) via ruby-core" <ruby-core@...>
Date:
2025-09-06 06:25:17 UTC
List:
ruby-core #123182
Issue #21562 has been updated by YO4 (Yoshinao Muramatsu).
PR here
https://github.com/ruby/ruby/pull/14455
----------------------------------------
Bug #21562: IO#each_codepoint raises using with IO#ungetc
https://bugs.ruby-lang.org/issues/21562#change-114513
* Author: YO4 (Yoshinao Muramatsu)
* Status: Open
* ruby -v: ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x64-mingw-ucrt]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Using IO#each_codepoint together with IO#ungetc causes ```byte oriented read for character buffered IO (IOError)``` when encoding conversion is active.
```
C:\>ruby -e "open('NUL', 'rt') { _1.ungetc('aa'); _1.each_codepoint { |c| p c }}"
97
-e:1:in 'IO#each_codepoint': byte oriented read for character buffered IO (IOError)
from -e:1:in 'block in <main>'
from -e:1:in 'Kernel#open'
from -e:1:in '<main>'
```
note: 'rt' enables newline conversion for input, and it uses the encoding conversion mechanism.
When encoding conversion is not used, similar operations complete successfully.
```
C:\>ruby -e "open('NUL', 'rb') { _1.ungetc('aa'); _1.each_codepoint { |c| p c }}"
97
97
```
Since both IO#each_codepoint and IO#ungetc handle characters, I believe IO#each_codepoint should work on both cases.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/