From: "andrykonchin (Andrew Konchin) via ruby-core" Date: 2024-04-09T17:14:13+00:00 Subject: [ruby-core:117478] [Ruby master Bug#20418] `StringIO#read(..., buffer)` doesn't preserve buffer's encoding Issue #20418 has been reported by andrykonchin (Andrew Konchin). ---------------------------------------- Bug #20418: `StringIO#read(..., buffer)` doesn't preserve buffer's encoding https://bugs.ruby-lang.org/issues/20418 * Author: andrykonchin (Andrew Konchin) * Status: Open * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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: ```ruby file = File.open('test.rb') buffer = "".encode(Encoding::ISO_8859_1) file.read(10, buffer) buffer.encoding # => # ``` ```ruby require 'stringio' io = StringIO.new("# encoding") buffer = "".encode(Encoding::ISO_8859_1) io.read(10, buffer) buffer.encoding # => # ``` I would expect StringIO's read and similar methods to preserve a buffer's encoding. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/