Project

General

Profile

Actions

Bug #3533

closed

Default external encoding not picked up by output unless internal encoding set

Added by pdwilson12 (Peter Wilson) over 14 years ago. Updated over 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2dev (2010-07-02 revision 28522) [x86_64-darwin10.4.0]
Backport:
[ruby-core:31034]

Description

=begin
ruby 1.9.2dev (2010-07-02 revision 28522) [x86_64-darwin10.4.0]

If I specify an external encoding with the -E option, the STDOUT and File.open output streams do not respect it. I have to explicitly assign an external encoding on the stream, otherwise strings written to the stream are not transcoded; instead the raw byes of the strings are written out. However, if I set a default internal encoding with the -E option, it all works. Strings with some arbitrary encoding are transcoded into the default external encoding when written to the stream.

I've attached a sample program illustrating this. It logs ruby's default encodings, the encodings of STDOUT and STDIN, and then writes an ISO-8859-1 and UTF-8 string to a new file opened without an explicit encoding. If I run the script with '-E utf-8', STDOUT and the file don't list any external encoding and the generated file has text of both encodings present. If I instead run it with '-E utf-8:utf-8', adding an internal encoding, all streams get the UTF-8 external encoding and the generated file contains the correct UTF-8 versions of both strings.
=end


Files

EncodingTest.rb (579 Bytes) EncodingTest.rb pdwilson12 (Peter Wilson), 07/04/2010 11:01 AM
Actions #1

Updated by runpaint (Run Paint Run Run) over 14 years ago

=begin
I believe both behaviours are intended.

As I note in http://ruby.runpaint.org/encoding#external , "The external encoding of a stream may be queried with IO#external_encoding, which returns the corresponding Encoding object. Note, however, that if the stream is in write-only mode, and wasn’t explicitly assigned an external encoding, this method returns nil."

When the internal encoding is nil, no transcoding occurs, and it is nil by default. If you want transcoding you must ask for it explicitly.
=end

Actions #2

Updated by naruse (Yui NARUSE) over 14 years ago

  • Status changed from Open to Rejected

=begin
Run Paint is right; it is intended.
=end

Actions #3

Updated by pdwilson12 (Peter Wilson) over 14 years ago

=begin
It is very odd that writeable IO objects (but not read-only IO objects) ignore the default external encoding unless a default internal encoding is set. But Ok.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0