Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserve external encoding of stdin on windows #1042

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
Development

Successfully merging this pull request may close these issues.

1 participant