ruby-changes:49524
From: normal <ko1@a...>
Date: Sat, 6 Jan 2018 18:21:39 +0900 (JST)
Subject: [ruby-changes:49524] normal:r61639 (trunk): net/ftp: fix FrozenError in BufferedSocket
normal 2018-01-06 18:21:35 +0900 (Sat, 06 Jan 2018) New Revision: 61639 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61639 Log: net/ftp: fix FrozenError in BufferedSocket I noticed this bug while working on something else with RUBYOPT=-d on, existing test cases all passed with it. Note: I use String.new because it is the local style, here, I prefer +'' (or ''.b, for a future commit) * lib/net/ftp.rb (BufferedSocket#read): use String.new * test/net/ftp/test_buffered_socket.rb (test_read_nil): new test [ruby-core:84675] [Bug #14323] Modified files: trunk/lib/net/ftp.rb trunk/test/net/ftp/test_buffered_socket.rb Index: lib/net/ftp.rb =================================================================== --- lib/net/ftp.rb (revision 61638) +++ lib/net/ftp.rb (revision 61639) @@ -1428,7 +1428,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L1428 s = super(len, String.new, true) return s.empty? ? nil : s else - result = "" + result = String.new while s = super(DEFAULT_BLOCKSIZE, String.new, true) break if s.empty? result << s Index: test/net/ftp/test_buffered_socket.rb =================================================================== --- test/net/ftp/test_buffered_socket.rb (revision 61638) +++ test/net/ftp/test_buffered_socket.rb (revision 61639) @@ -33,6 +33,12 @@ class BufferedSocketTest < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_buffered_socket.rb#L33 assert_equal("bar", sock.gets) end + def test_read_nil + sock = create_buffered_socket("foo\nbar") + assert_equal("foo\nbar", sock.read) + assert_equal("", sock.read) + end + private def create_buffered_socket(s) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/