From 32ecaac7b18cc5f0b0cee90801819b8e53930870 Mon Sep 17 00:00:00 2001 From: usa Date: Fri, 28 Nov 2014 07:11:26 +0000 Subject: [PATCH] merge revision(s) 42709: [Backport #10529] * io.c (copy_stream_body): should write in binary mode. based on a patch by godfat (Lin Jen-Shin) at [ruby-core:56556]. [ruby-core:56518] [Bug #8767] * io.c (copy_stream_body): move common open flags. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@48631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ io.c | 4 ++-- test/ruby/test_io.rb | 41 +++++++++++++++++++++++++++++++++++++++++ version.h | 2 +- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e391d54656..9093b02937 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Nov 28 16:05:09 2014 Nobuyoshi Nakada + + * io.c (copy_stream_body): should write in binary mode. based on a + patch by godfat (Lin Jen-Shin) at [ruby-core:56556]. + [ruby-core:56518] [Bug #8767] + +Fri Nov 28 16:05:09 2014 Nobuyoshi Nakada + + * io.c (copy_stream_body): move common open flags. + Fri Nov 28 16:01:44 2014 NAKAMURA Usaku * lib/rubygems/ssl_certs/AddTrustExternalCARoot{-2048,}.pem: add newer diff --git a/io.c b/io.c index 4757331f17..786b8883a8 100644 --- a/io.c +++ b/io.c @@ -10208,9 +10208,9 @@ copy_stream_body(VALUE arg) #ifdef O_BINARY if (src_fptr) SET_BINARY_MODE_WITH_SEEK_CUR(src_fptr); - if (dst_fptr) - setmode(dst_fd, O_BINARY); #endif + if (dst_fptr) + rb_io_ascii8bit_binmode(dst_io); if (stp->src_offset == (off_t)-1 && src_fptr && src_fptr->rbuf.len) { size_t len = src_fptr->rbuf.len; diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 89e347d2b3..acd7e654d4 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -770,6 +770,47 @@ class TestIO < Test::Unit::TestCase } end + def test_copy_stream_write_in_binmode + bug8767 = '[ruby-core:56518] [Bug #8767]' + mkcdtmpdir { + EnvUtil.with_default_internal(Encoding::UTF_8) do + # StringIO to object with to_path + bytes = "\xDE\xAD\xBE\xEF".force_encoding(Encoding::ASCII_8BIT) + src = StringIO.new(bytes) + dst = Object.new + def dst.to_path + "qux" + end + assert_nothing_raised(bug8767) { + IO.copy_stream(src, dst) + } + assert_equal(bytes, File.binread("qux"), bug8767) + assert_equal(4, src.pos, bug8767) + end + } + end + + def test_copy_stream_read_in_binmode + bug8767 = '[ruby-core:56518] [Bug #8767]' + mkcdtmpdir { + EnvUtil.with_default_internal(Encoding::UTF_8) do + # StringIO to object with to_path + bytes = "\xDE\xAD\xBE\xEF".force_encoding(Encoding::ASCII_8BIT) + File.binwrite("qux", bytes) + dst = StringIO.new + src = Object.new + def src.to_path + "qux" + end + assert_nothing_raised(bug8767) { + IO.copy_stream(src, dst) + } + assert_equal(bytes, dst.string.b, bug8767) + assert_equal(4, dst.pos, bug8767) + end + } + end + class Rot13IO def initialize(io) @io = io diff --git a/version.h b/version.h index 20e4531358..a89be87f6d 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-11-28" -#define RUBY_PATCHLEVEL 600 +#define RUBY_PATCHLEVEL 601 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 11