ruby-changes:47461
From: nobu <ko1@a...>
Date: Sat, 12 Aug 2017 10:47:15 +0900 (JST)
Subject: [ruby-changes:47461] nobu:r59578 (trunk): stringio.c: encoding at EOF
nobu 2017-08-12 10:47:09 +0900 (Sat, 12 Aug 2017) New Revision: 59578 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59578 Log: stringio.c: encoding at EOF * ext/stringio/stringio.c (strio_read): should return string with the external encoding, at EOF too. [ruby-core:82349] [Bug #13806] Modified files: trunk/ext/stringio/stringio.c trunk/test/stringio/test_stringio.rb Index: test/stringio/test_stringio.rb =================================================================== --- test/stringio/test_stringio.rb (revision 59577) +++ test/stringio/test_stringio.rb (revision 59578) @@ -577,6 +577,13 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/stringio/test_stringio.rb#L577 s = "0123456789" assert_same(s, f.read(nil, s)) assert_equal("\u3042\u3044", s) + + bug13806 = '[ruby-core:82349] [Bug #13806]' + assert_string("", Encoding::UTF_8, f.read, bug13806) + assert_string("", Encoding::UTF_8, f.read(nil, nil), bug13806) + s.force_encoding(Encoding::US_ASCII) + assert_same(s, f.read(nil, s)) + assert_string("", Encoding::UTF_8, s, bug13806) end def test_readpartial @@ -756,4 +763,8 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/stringio/test_stringio.rb#L763 assert_equal(0x100000, s.pos) end; end + + def assert_string(content, encoding, str, mesg = nil) + assert_equal([content, encoding], [str, str.encoding], mesg) + end end Index: ext/stringio/stringio.c =================================================================== --- ext/stringio/stringio.c (revision 59577) +++ ext/stringio/stringio.c (revision 59578) @@ -1392,12 +1392,14 @@ strio_read(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L1392 case 0: len = RSTRING_LEN(ptr->string); if (len <= ptr->pos) { + rb_encoding *enc = binary ? rb_ascii8bit_encoding() : get_enc(ptr); if (NIL_P(str)) { str = rb_str_new(0, 0); } else { rb_str_resize(str, 0); } + rb_enc_associate(str, enc); return str; } else { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/