Skip to content

Conversation

@YO4
Copy link
Contributor

@YO4 YO4 commented Dec 3, 2024

irb changes $stdin.{external,internal}_encoding.
This causes gets() to no longer return the correct content in irb running on windows.

C:\>chcp
現在のコード ページ: 932

C:\>ruby -e "p [STDIN.external_encoding, STDIN.internal_encoding]"
[#<Encoding:Windows-31J>, #<Encoding:UTF-8>]

C:\>ruby -e "gets.then { p [_1, _1.encoding] }"
あ
["あ\n", #<Encoding:UTF-8>]

C:\>irb
irb(main):001> p [STDIN.external_encoding, STDIN.internal_encoding];
[#<Encoding:UTF-8>, nil]
irb(main):002> gets.then { p [_1, _1.encoding] };
あ
["\x82\xA0\n", #<Encoding:UTF-8>]
irb(main):003>

I have made a patch.
However, I am not sure if this will work for all situations, since I did not understand all the responsibilities of the original code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant