Project

General

Profile

Actions

Bug #20418

closed

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

Added by andrykonchin (Andrew Konchin) 9 months ago. Updated 8 months 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

Also available in: Atom PDF

Like0
Like1Like0