From: nobu@... Date: 2016-11-29T04:02:38+00:00 Subject: [ruby-core:78409] [Ruby trunk Bug#12989] Passing `binmode: true` to `IO.pipe` makes `binmode?` return `true` but encoding is not binary Issue #12989 has been updated by Nobuyoshi Nakada. Description updated Encoding argument should be prior to `binmode` option. ```ruby $ ruby -e 'open(IO::NULL, "r", binmode: true){|f| p [f.binmode?, f.external_encoding]}' [true, #] $ ruby -e 'open(IO::NULL, "r:utf-8", binmode: true){|f| p [f.binmode?, f.external_encoding]}' [true, #] ``` Your patch always makes `external_encoding` `ASCII-8BIT` when `binmode` is set, even if an encoding is given. ---------------------------------------- Bug #12989: Passing `binmode: true` to `IO.pipe` makes `binmode?` return `true` but encoding is not binary https://bugs.ruby-lang.org/issues/12989#change-61782 * Author: Aaron Patterson * Status: Open * Priority: Normal * Assignee: * ruby -v: ruby 2.4.0dev (2016-11-16 gc-compact 56805) [x86_64-darwin16] * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- Here is a sample program: ~~~ruby Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 reader, writer = IO.pipe(binmode: true) reader.binmode? # => true reader.external_encoding # => # writer.binmode? # => true writer.external_encoding # => # reader, writer = IO.pipe reader.binmode writer.binmode reader.binmode? # => true reader.external_encoding # => # writer.binmode? # => true writer.external_encoding # => # ~~~ I think that passing `binmode: true` to `IO.pipe` should behave the same way as calling `binmode` on each file. Today, passing `binmode: true` to IO.pipe puts the files in a strange state: they are binary and not binary. I've attached a patch to fix the problem. ---Files-------------------------------- 0001-Passing-binmode-true-to-IO.pipe-should-behave-like-b.patch (2.5 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: