[ruby-core:78409] [Ruby trunk Bug#12989] Passing `binmode: true` to `IO.pipe` makes `binmode?` return `true` but encoding is not binary
From:
nobu@...
Date:
2016-11-29 04:02:38 UTC
List:
ruby-core #78409
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, #<Encoding:ASCII-8BIT>]
$ ruby -e 'open(IO::NULL, "r:utf-8", binmode: true){|f| p [f.binmode?, f.external_encoding]}'
[true, #<Encoding:UTF-8>]
```
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 # => #<Encoding:UTF-8>
writer.binmode? # => true
writer.external_encoding # => #<Encoding:UTF-8>
reader, writer = IO.pipe
reader.binmode
writer.binmode
reader.binmode? # => true
reader.external_encoding # => #<Encoding:ASCII-8BIT>
writer.binmode? # => true
writer.external_encoding # => #<Encoding:ASCII-8BIT>
~~~
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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>