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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2018-01-06 09:21:35 +00:00
parent 7d34bdb81d
commit e56d34001f
2 changed files with 7 additions and 1 deletions

View File

@ -1428,7 +1428,7 @@ module Net
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

View File

@ -33,6 +33,12 @@ class BufferedSocketTest < Test::Unit::TestCase
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)