Project

General

Profile

Actions

Bug #20418

closed

`StringIO#read(..., buffer)` doesn't preserve buffer's encoding

Added by andrykonchin (Andrew Konchin) 21 days ago. Updated 14 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:117478]

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.

Actions #2

Updated by Anonymous 14 days 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)

[Bug #20418]

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

Actions

Also available in: Atom PDF

Like0
Like1Like0