Issue #13124 has been updated by Yui NARUSE.


On current Ruby, IO converts given string only if the IO object is set internal_encoding.
Therefore the behavior is spec.

Yes, the spec is not clear.
I continually inspecting the use cases and implementation to re-design IO encodings, but it still needs further inspection...

I partially wrote that at https://bugs.ruby-lang.org/issues/7201#note-5

----------------------------------------
Feature #13124: Should #puts convert to external encoding?
https://bugs.ruby-lang.org/issues/13124#change-62552

* Author: Benoit Daloze
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 2.5
----------------------------------------
For instance:

    puts "?\x00\x42\x30".force_encoding(Encoding::UTF_16LE)
    ?B0

    puts "?\x00\x42\x30".force_encoding(Encoding::UTF_16LE).encode("utf-8")
    ?дв

The first result is surprising to me. It seems to treat the String as raw bytes and just "assume" they are displayable in the external encoding.

Should #puts re-encode the String to print in Encoding.default_external or the locale encoding?

    STDOUT.set_encoding(Encoding.find("locale"))

seems to do what I expect, but should that be the default?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>