summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--lib/net/ftp.rb16
-rw-r--r--test/net/ftp/test_ftp.rb28
3 files changed, 40 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 57892f8fc9..58d3c6569d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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