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

ruby-changes:39759

From: shugo <ko1@a...>
Date: Sat, 12 Sep 2015 18:16:28 +0900 (JST)
Subject: [ruby-changes:39759] shugo:r51840 (trunk): * lib/net/ftp.rb (parse_mlsx_entry, mlst) raise an FTPProtoError

shugo	2015-09-12 18:16:21 +0900 (Sat, 12 Sep 2015)

  New Revision: 51840

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

  Log:
    * lib/net/ftp.rb (parse_mlsx_entry, mlst) raise an FTPProtoError
      when parsing failed.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51839)
+++ ChangeLog	(revision 51840)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Sep 12 18:14:11 2015  Shugo Maeda  <shugo@r...>
+
+	* lib/net/ftp.rb (parse_mlsx_entry, mlst) raise an FTPProtoError
+	  when parsing failed.
+
 Sat Sep 12 18:00:35 2015  Shugo Maeda  <shugo@r...>
 
 	* lib/net/ftp.rb (TIME_PARSER): use "Z" instead of "+00:00" to
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 51839)
+++ lib/net/ftp.rb	(revision 51840)
@@ -795,6 +795,9 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L795
 
     def parse_mlsx_entry(entry)
       facts, pathname = entry.split(" ")
+      unless pathname
+        raise FTPProtoError, entry
+      end
       return MLSxEntry.new(
         facts.scan(/(.*?)=(.*?);/).each_with_object({}) {
           |(factname, value), h|
@@ -816,7 +819,11 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L819
       if !resp.start_with?("250")
         raise FTPReplyError, resp
       end
-      entry = resp.lines[1].sub(/\A(250-| *)/, "")
+      line = resp.lines[1]
+      unless line
+        raise FTPProtoError, resp
+      end
+      entry = line.sub(/\A(250-| *)/, "")
       return parse_mlsx_entry(entry)
     end
 
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 51839)
+++ test/net/ftp/test_ftp.rb	(revision 51840)
@@ -1127,12 +1127,23 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1127
       sock.print("250- Listing foo\r\n")
       sock.print(" Type=file;Unique=FC00U1E554A;Size=1234567;Modify=20131220035929;Perm=r; /foo\r\n")
       sock.print("250 End\r\n")
+      commands.push(sock.gets)
+      sock.print("250 Malformed response\r\n")
+      commands.push(sock.gets)
+      sock.print("250- Listing foo\r\n")
+      sock.print("\r\n")
+      sock.print("250 End\r\n")
+      commands.push(sock.gets)
+      sock.print("250- Listing foo\r\n")
+      sock.print(" abc /foo\r\n")
+      sock.print("250 End\r\n")
     }
     begin
       begin
         ftp = Net::FTP.new
         ftp.connect(SERVER_ADDR, server.port)
         entry = ftp.mlst("foo")
+        assert_equal("/foo", entry.pathname)
         assert_equal("file", entry.facts["type"])
         assert_equal("FC00U1E554A", entry.facts["unique"])
         assert_equal(1234567, entry.facts["size"])
@@ -1146,6 +1157,17 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1157
         assert_equal(29, modify.sec)
         assert_equal(true, modify.utc?)
         assert_match("MLST foo\r\n", commands.shift)
+        assert_raise(Net::FTPProtoError) do
+          ftp.mlst("foo")
+        end
+        assert_match("MLST foo\r\n", commands.shift)
+        assert_raise(Net::FTPProtoError) do
+          ftp.mlst("foo")
+        end
+        assert_match("MLST foo\r\n", commands.shift)
+        entry = ftp.mlst("foo")
+        assert_equal("/foo", entry.pathname)
+        assert_match("MLST foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
         ftp.close if ftp
@@ -1204,6 +1226,9 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1226
         assert_equal("TYPE I\r\n", commands.shift)
         entries = ftp.mlsd("/")
         assert_equal(3, entries.size)
+        assert_equal("foo", entries[0].pathname)
+        assert_equal(".", entries[1].pathname)
+        assert_equal("..", entries[2].pathname)
         assert_equal("file", entries[0].facts["type"])
         assert_equal("cdir", entries[1].facts["type"])
         assert_equal("pdir", entries[2].facts["type"])

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

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