Actions
Bug #21562
openIO#each_codepoint raises using with IO#ungetc
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x64-mingw-ucrt]
Description
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.
Updated by YO4 (Yoshinao Muramatsu) 2 days ago
Actions
Like0
Like0