diff options
author | Jean byroot Boussier <[email protected]> | 2024-04-17 03:29:09 +0200 |
---|---|---|
committer | git <[email protected]> | 2024-04-17 01:29:18 +0000 |
commit | 75154dec73e1329693866e3a88cb9febb7635417 (patch) | |
tree | de4ed05b715f2ce51f322cf2fce13eacaa019b46 /ext/stringio | |
parent | f34409bf8782481deabec6c577abd66373134af9 (diff) |
[ruby/stringio] strio_read: preserve buffer encoding on partial
reads
(https://github.com/ruby/stringio/pull/95)
[[Bug #20418]](https://bugs.ruby-lang.org/issues/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 <[email protected]>
Diffstat (limited to 'ext/stringio')
-rw-r--r-- | ext/stringio/stringio.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index f0e5ee4e85..820b8228a3 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1623,10 +1623,9 @@ strio_read(int argc, VALUE *argv, VALUE self) if (len > rest) len = rest; rb_str_resize(str, len); MEMCPY(RSTRING_PTR(str), RSTRING_PTR(ptr->string) + ptr->pos, char, len); - if (binary) - rb_enc_associate(str, rb_ascii8bit_encoding()); - else + if (!binary) { rb_enc_copy(str, ptr->string); + } } ptr->pos += RSTRING_LEN(str); return str; |