ruby-changes:47464
From: nobu <ko1@a...>
Date: Sun, 13 Aug 2017 16:21:19 +0900 (JST)
Subject: [ruby-changes:47464] nobu:r59581 (trunk): stringio.c: encoding at empty result
nobu 2017-08-13 16:21:13 +0900 (Sun, 13 Aug 2017) New Revision: 59581 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59581 Log: stringio.c: encoding at empty result * ext/stringio/stringio.c (strio_gets): should return string with the external encoding, at empty result. Modified files: trunk/ext/stringio/stringio.c trunk/test/stringio/test_stringio.rb Index: ext/stringio/stringio.c =================================================================== --- ext/stringio/stringio.c (revision 59580) +++ ext/stringio/stringio.c (revision 59581) @@ -1149,7 +1149,8 @@ strio_gets(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L1149 VALUE str; if (prepare_getline_args(&arg, argc, argv)->limit == 0) { - return rb_str_new(0, 0); + struct StringIO *ptr = readable(self); + return rb_enc_str_new(0, 0, get_enc(ptr)); } str = strio_getline(&arg, readable(self)); Index: test/stringio/test_stringio.rb =================================================================== --- test/stringio/test_stringio.rb (revision 59580) +++ test/stringio/test_stringio.rb (revision 59581) @@ -79,6 +79,8 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/stringio/test_stringio.rb#L79 assert_equal("def\n", stringio.gets("")) assert_raise(TypeError){StringIO.new("").gets(1, 1)} assert_nothing_raised {StringIO.new("").gets(nil, nil)} + + assert_string("", Encoding::UTF_8, StringIO.new("foo").gets(0)) end def test_gets_chomp -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/