From: "YO4 (Yoshinao Muramatsu) via ruby-core" Date: 2025-09-04T11:05:31+00:00 Subject: [ruby-core:123176] [Ruby Bug#21562] IO#each_codepoint raises using with IO#ungetc Issue #21562 has been reported by YO4 (Yoshinao Muramatsu). ---------------------------------------- Bug #21562: IO#each_codepoint raises using with IO#ungetc https://bugs.ruby-lang.org/issues/21562 * 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
' from -e:1:in 'Kernel#open' from -e:1:in '
' ``` 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/