Skip to content

Commit

Permalink
preserve external encoding of stdin on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
YO4 committed Dec 3, 2024
1 parent 0506ed0 commit ecd6004
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,14 @@ def set_encoding(extern, intern = nil, override: true)
Encoding.default_external = extern unless extern.nil? || extern.empty?
Encoding.default_internal = intern unless intern.nil? || intern.empty?
[$stdin, $stdout, $stderr].each do |io|
io.set_encoding(extern, intern)
if io.tty? && io.internal_encoding && /mswin|mingw/ =~ RUBY_PLATFORM
# some ruby versions, $stdin has locale:UTF-8 encoding by default on windows.
# preserve external_encoding in that case.
io.set_encoding(io.external_encoding, (intern.nil? || intern.empty?) ? extern : intern)
next
else
io.set_encoding(extern, intern)
end
end
if override
@CONF[:LC_MESSAGES].instance_variable_set(:@override_encoding, extern)
Expand Down

0 comments on commit ecd6004

Please sign in to comment.