ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:117478] [Ruby master Bug#20418] `StringIO#read(..., buffer)` doesn't preserve buffer's encoding
@ 2024-04-09 17:14 andrykonchin (Andrew Konchin) via ruby-core
  2024-04-11 14:17 ` [ruby-core:117493] " byroot (Jean Boussier) via ruby-core
  0 siblings, 1 reply; 2+ messages in thread
From: andrykonchin (Andrew Konchin) via ruby-core @ 2024-04-09 17:14 UTC (permalink / raw
  To: ruby-core; +Cc: andrykonchin (Andrew Konchin)

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 # => #<Encoding:ISO-8859-1>
```

```ruby
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.



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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:117493] [Ruby master Bug#20418] `StringIO#read(..., buffer)` doesn't preserve buffer's encoding
  2024-04-09 17:14 [ruby-core:117478] [Ruby master Bug#20418] `StringIO#read(..., buffer)` doesn't preserve buffer's encoding andrykonchin (Andrew Konchin) via ruby-core
@ 2024-04-11 14:17 ` byroot (Jean Boussier) via ruby-core
  0 siblings, 0 replies; 2+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2024-04-11 14:17 UTC (permalink / raw
  To: ruby-core; +Cc: byroot (Jean Boussier)

Issue #20418 has been updated by byroot (Jean Boussier).


Seems legit to me. Proposed patch: https://github.com/ruby/stringio/pull/95

----------------------------------------
Bug #20418: `StringIO#read(..., buffer)` doesn't preserve buffer's encoding
https://bugs.ruby-lang.org/issues/20418#change-107883

* 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 # => #<Encoding:ISO-8859-1>
```

```ruby
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.



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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-11 14:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09 17:14 [ruby-core:117478] [Ruby master Bug#20418] `StringIO#read(..., buffer)` doesn't preserve buffer's encoding andrykonchin (Andrew Konchin) via ruby-core
2024-04-11 14:17 ` [ruby-core:117493] " byroot (Jean Boussier) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).