Project

General

Profile

Actions

Feature #13124

open

Should #puts convert to external encoding?

Added by Eregon (Benoit Daloze) almost 8 years ago. Updated almost 7 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:79055]

Description

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?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0