diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-10 06:16:37 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-10 06:16:37 +0000 |
commit | 5e89098eafc48b6fb2995f14549f36c50fe53333 (patch) | |
tree | d4bfaeb0dc97282635c83460437faa80d4f2a36a | |
parent | 26bf5f44d6cd66de9fd23d2a8d79b4236c5c95ed (diff) | |
download | ruby-5e89098eafc48b6fb2995f14549f36c50fe53333.tar.gz |
* lib/net/ftp.rb (getmultiline): refactor.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/net/ftp.rb | 16 | ||||
-rw-r--r-- | test/net/ftp/test_ftp.rb | 28 |
3 files changed, 40 insertions, 8 deletions
@@ -1,3 +1,7 @@ +Thu Sep 10 15:16:02 2015 Shugo Maeda <shugo@ruby-lang.org> + + * lib/net/ftp.rb (getmultiline): refactor. + Thu Sep 10 12:17:28 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> * compile.c (iseq_build_from_ary_body): register cdhash to the diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 724f4b85bd..3c3353e9fe 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -298,16 +298,16 @@ module Net # Receive a section of lines until the response code's match. def getmultiline # :nodoc: - line = getline - buff = line - if line[3] == ?- - code = line[0, 3] + lines = [] + lines << getline + code = lines.last.slice(/\A([0-9a-zA-Z]{3})-/, 1) + if code + delimiter = code + " " begin - line = getline - buff << "\n" << line - end until line[0, 3] == code and line[3] != ?- + lines << getline + end until lines.last.start_with?(delimiter) end - return buff << "\n" + return lines.join("\n") + "\n" end private :getmultiline diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb index ad8ef5aa37..e42168e6dc 100644 --- a/test/net/ftp/test_ftp.rb +++ b/test/net/ftp/test_ftp.rb @@ -1025,6 +1025,34 @@ EOF end end + def test_getmultiline + server = create_ftp_server { |sock| + sock.print("220 (test_ftp).\r\n") + sock.print("123- foo\r\n") + sock.print("bar\r\n") + sock.print(" 123 baz\r\n") + sock.print("123 quux\r\n") + sock.print("123 foo\r\n") + sock.print("foo\r\n") + sock.print("\r\n") + } + begin + begin + ftp = Net::FTP.new + ftp.connect(SERVER_ADDR, server.port) + assert_equal("123- foo\nbar\n 123 baz\n123 quux\n", + ftp.send(:getmultiline)) + assert_equal("123 foo\n", ftp.send(:getmultiline)) + assert_equal("foo\n", ftp.send(:getmultiline)) + assert_equal("\n", ftp.send(:getmultiline)) + ensure + ftp.close if ftp + end + ensure + server.close + end + end + private |