Bug #20418
closed`StringIO#read(..., buffer)` doesn't preserve buffer's encoding
Description
IO#read (and similar methods #read_nonblock
, #readpartial
, #sysread
) when called with a buffer
argument preserve its encoding. But StringIO#read
doesn't do so:
file = File.open('test.rb')
buffer = "".encode(Encoding::ISO_8859_1)
file.read(10, buffer)
buffer.encoding # => #<Encoding:ISO-8859-1>
require 'stringio'
io = StringIO.new("# encoding")
buffer = "".encode(Encoding::ISO_8859_1)
io.read(10, buffer)
buffer.encoding # => #<Encoding:ASCII-8BIT>
I would expect StringIO's read and similar methods to preserve a buffer's encoding.
Updated by byroot (Jean Boussier) 4 months ago
Seems legit to me. Proposed patch: https://github.com/ruby/stringio/pull/95
Updated by Anonymous 4 months ago
- Status changed from Open to Closed
Applied in changeset git|75154dec73e1329693866e3a88cb9febb7635417.
[ruby/stringio] strio_read: preserve buffer encoding on partial
reads
(https://github.com/ruby/stringio/pull/95)
Ruby IO#read preserves the encoding on partial read, but change it when
reading the whole IO
from commit https://github.com/ruby/ruby/commit/0ca7036682da:
- io.c (read_all): should associate default external encoding.
- io.c (io_read): should NOT associate default external encoding.
https://github.com/ruby/stringio/commit/073172da31
Co-authored-by: Jean Boussier jean.boussier@gmail.com