aboutsummaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorJean byroot Boussier <jean.boussier+github@shopify.com>2024-04-17 03:29:09 +0200
committergit <svn-admin@ruby-lang.org>2024-04-17 01:29:18 +0000
commit75154dec73e1329693866e3a88cb9febb7635417 (patch)
treede4ed05b715f2ce51f322cf2fce13eacaa019b46 /ext
parentf34409bf8782481deabec6c577abd66373134af9 (diff)
downloadruby-75154dec73e1329693866e3a88cb9febb7635417.tar.gz
[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 <jean.boussier@gmail.com>
Diffstat (limited to 'ext')
-rw-r--r--ext/stringio/stringio.c5
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;