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

ruby-changes:40014

From: shugo <ko1@a...>
Date: Fri, 9 Oct 2015 17:29:44 +0900 (JST)
Subject: [ruby-changes:40014] shugo:r52095 (trunk): * lib/net/ftp.rb (parse257): refactor.

shugo	2015-10-09 17:29:36 +0900 (Fri, 09 Oct 2015)

  New Revision: 52095

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

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

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52094)
+++ ChangeLog	(revision 52095)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct  9 17:29:07 2015  Shugo Maeda  <shugo@r...>
+
+	* lib/net/ftp.rb (parse257): refactor.
+
 Fri Oct  9 16:42:26 2015  Shugo Maeda  <shugo@r...>
 
 	* lib/net/imap.rb: use frozen_string_literal: true.
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 52094)
+++ lib/net/ftp.rb	(revision 52095)
@@ -1246,24 +1246,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L1246
       if !resp.start_with?("257")
         raise FTPReplyError, resp
       end
-      if resp[3, 2] != ' "'
-        return ""
-      end
-      dirname = ""
-      i = 5
-      n = resp.length
-      while i < n
-        c = resp[i, 1]
-        i = i + 1
-        if c == '"'
-          if i > n or resp[i, 1] != '"'
-            break
-          end
-          i = i + 1
-        end
-        dirname = dirname + c
-      end
-      return dirname
+      return resp.slice(/"(([^"]|"")*)"/, 1).to_s.gsub(/""/, '"')
     end
     private :parse257
 
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 52094)
+++ test/net/ftp/test_ftp.rb	(revision 52095)
@@ -1318,8 +1318,26 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1318
     end
   end
 
-  private
+  def test_parse257
+    ftp = Net::FTP.new
+    assert_equal('/foo/bar',
+                 ftp.send(:parse257, '257 "/foo/bar" directory created'))
+    assert_equal('/foo/bar"baz',
+                 ftp.send(:parse257, '257 "/foo/bar""baz" directory created'))
+    assert_equal('/foo/x"y"z',
+                 ftp.send(:parse257, '257 "/foo/x""y""z" directory created'))
+    assert_equal('/foo/bar',
+                 ftp.send(:parse257, '257 "/foo/bar" "comment"'))
+    assert_equal('',
+                 ftp.send(:parse257, '257 "" directory created'))
+    assert_equal('',
+                 ftp.send(:parse257, '257 directory created'))
+    assert_raise(Net::FTPReplyError) do
+      ftp.send(:parse257, "500 Syntax error")
+    end
+  end
 
+  private
 
   def create_ftp_server(sleep_time = nil)
     server = TCPServer.new(SERVER_ADDR, 0)

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

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