[前][次][番号順一覧][スレッド一覧]

ruby-changes:39737

From: shugo <ko1@a...>
Date: Thu, 10 Sep 2015 15:17:00 +0900 (JST)
Subject: [ruby-changes:39737] shugo:r51818 (trunk): * lib/net/ftp.rb (getmultiline): refactor.

shugo	2015-09-10 15:16:37 +0900 (Thu, 10 Sep 2015)

  New Revision: 51818

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51818

  Log:
    * lib/net/ftp.rb (getmultiline): refactor.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51817)
+++ ChangeLog	(revision 51818)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Sep 10 15:16:02 2015  Shugo Maeda  <shugo@r...>
+
+	* lib/net/ftp.rb (getmultiline): refactor.
+
 Thu Sep 10 12:17:28 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* compile.c (iseq_build_from_ary_body): register cdhash to the
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 51817)
+++ lib/net/ftp.rb	(revision 51818)
@@ -298,16 +298,16 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L298
 
     # 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
 
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 51817)
+++ test/net/ftp/test_ftp.rb	(revision 51818)
@@ -1025,6 +1025,34 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1025
     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
 
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]