Project

General

Profile

Actions

Bug #20067

open

IO.pipe `int_enc` and `ext_enc` not working as documented?

Added by byroot (Jean Boussier) 11 months ago. Updated 11 months ago.

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

Description

From the documentation:

pipe(ext_enc, int_enc, **opts)

If argument int_enc is given, it must be an Encoding object or encoding name string that specifies the internal encoding to be used; if argument ext_enc is also given, it must be an Encoding object or encoding name string that specifies the external encoding to be used.

Test script:

ios = IO.pipe(Encoding::BINARY, Encoding::BINARY)

p [:internal, *ios.map(&:internal_encoding)]
p [:external, *ios.map(&:external_encoding)]

Encoding.default_internal = Encoding::UTF_8
Encoding.default_external = Encoding::UTF_8

ios = IO.pipe(Encoding::BINARY, Encoding::BINARY)

p [:internal, *ios.map(&:internal_encoding)]
p [:external, *ios.map(&:external_encoding)]

Actual output:

[:internal, nil, nil]
[:external, #<Encoding:ASCII-8BIT>, nil]
[:internal, nil, nil]
[:external, #<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>]

Expected output:

[:internal, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]
[:external, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]
[:internal, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]
[:external, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]

Am I reading the documentation incorrectly, or is it just not working as claimed?

I tried on older versions, and it seems to have been like that all the way down to Ruby 1.9.

The only reliable way I found to have a "binary" pipe is to call IO#binmode.

Actions

Also available in: Atom PDF

Like0
Like0