From: "YO4 (Yoshinao Muramatsu) via ruby-core" Date: 2024-11-22T14:47:34+00:00 Subject: [ruby-core:119994] [Ruby master Feature#19191] Implicit console input transcoding is more desirable Issue #19191 has been updated by YO4 (Yoshinao Muramatsu). irb changes $stdin.{external,internal}_encoding. This causes gets() to no longer return the correct content in irb. ``` C:\>chcp ������������������ ���������: 932 C:\>ruby -e "p [STDIN.external_encoding, STDIN.internal_encoding]" [#, #] C:\>ruby -e "gets.then { p [_1, _1.encoding] }" ��� ["���\n", #] C:\>irb irb(main):001> p [STDIN.external_encoding, STDIN.internal_encoding]; [#, nil] irb(main):002> gets.then { p [_1, _1.encoding] }; ��� ["\x82\xA0\n", #] irb(main):003> ``` It seems that making changes on the irb side would have a negative impact on test, etc. I think it is more reliable to deal with this on the ruby.exe side. ---------------------------------------- Feature #19191: Implicit console input transcoding is more desirable https://bugs.ruby-lang.org/issues/19191#change-110735 * Author: YO4 (Yoshinao Muramatsu) * Status: Open ---------------------------------------- In response to Bug #18353, STDIN.internal_encoding are set and encoding is converted explcitly on Windows platform. For example, ```[STDIN.external_encoding, STDIN.internal_encoding] # => [Encoding::Windows-31J, Encoding::UTF-8]``` if STDIN is console. I feel that internal_encoding should be reserved for specific applications. And I think setting internal_encoding to STDIN is not foreseened. Today I found irb breaks STDIN encoding, like ``` >ruby -rirb -e "p [$stdin.external_encoding, $stdin.internal_encoding]; IRB.setup(''); IRB::Irb.new(); p [$stdin.external_encoding, $stdin.internal_encoding]" [#, #] [#, nil] ``` We know input has console code page encoding. So we always can convert encoding from console code page to io_input_encoding(). ### proposal when reading from console on Windows, input encoding is enfoced to console code page and encoding conversion is implicitly applied. when ```set_encoding("UTF-8")``` implicitly converts console code page to UTF-8. when ```set_encoding("CP437", "UTF-8")``` implicitly converts console code page to UTF-8. external_encoding is ignored. binmode or binary input method is not affected by these specifications. set_encoding, etc. will continue to work as before, and this specification will affect only when encoding conversion on read (NEED_READCONV() and make_readconv()). -- 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/