ruby-changes:70396
From: Samuel <ko1@a...>
Date: Tue, 21 Dec 2021 08:26:08 +0900 (JST)
Subject: [ruby-changes:70396] da46b8d8e5 (master): Default `IO::Buffer#get_string` to use BINARY encoding.
https://git.ruby-lang.org/ruby.git/commit/?id=da46b8d8e5 From da46b8d8e5d09f896fb1af5dabea12820f02b3d6 Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Mon, 20 Dec 2021 12:17:38 +1300 Subject: Default `IO::Buffer#get_string` to use BINARY encoding. --- io_buffer.c | 2 +- test/ruby/test_io_buffer.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/io_buffer.c b/io_buffer.c index 075a9bfb786..63f5bd2c249 100644 --- a/io_buffer.c +++ b/io_buffer.c @@ -1125,7 +1125,7 @@ io_buffer_get_string(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/io_buffer.c#L1125 size_t offset = 0; size_t length = data->size; - rb_encoding *encoding = NULL; + rb_encoding *encoding = rb_ascii8bit_encoding(); if (argc >= 1) { offset = NUM2SIZET(argv[0]); diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index 0a8685d9d53..f2b9ca45e13 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -71,7 +71,10 @@ class TestIOBuffer < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_buffer.rb#L71 def test_file_mapped buffer = File.open(__FILE__) {|file| IO::Buffer.map(file)} - assert_include buffer.get_string, "Hello World" + contents = buffer.get_string + + assert_include contents, "Hello World" + assert_equal Encoding::BINARY, contents.encoding end def test_file_mapped_invalid -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/