Issue #12989 has been updated by nobu (Nobuyoshi Nakada).


jeremyevans0 (Jeremy Evans) wrote:
> Here's an updated patch based on tenderlove's original patch that does not change the encoding of the returned IO objects if encoding arguments are given in addition to the `binmode` option. Is this acceptable?

I think so.
In general, dedicated assertion methods e.g.,`assert_predicate` would be preferable to mere `assert`, I think.

----------------------------------------
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-80273

* Author: tenderlovemaking (Aaron Patterson)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
* 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)
io-pipe-binmode.patch (2.87 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>