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

ruby-changes:23089

From: shugo <ko1@a...>
Date: Mon, 26 Mar 2012 23:39:27 +0900 (JST)
Subject: [ruby-changes:23089] shugo:r35139 (trunk): * lib/net/ftp.rb (parse_pasv_port): refactored.

shugo	2012-03-26 23:39:16 +0900 (Mon, 26 Mar 2012)

  New Revision: 35139

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

  Log:
    * lib/net/ftp.rb (parse_pasv_port): refactored.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35138)
+++ ChangeLog	(revision 35139)
@@ -1,3 +1,7 @@
+Mon Mar 26 23:19:03 2012  Shugo Maeda  <shugo@r...>
+
+	* lib/net/ftp.rb (parse_pasv_port): refactored.
+
 Mon Mar 26 19:49:49 2012  Shugo Maeda  <shugo@r...>
 
 	* test/net/ftp/test_ftp.rb: add the test, which was forgotten in the
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 35138)
+++ lib/net/ftp.rb	(revision 35139)
@@ -963,8 +963,9 @@
     private :parse_pasv_ipv6_host
 
     def parse_pasv_port(s)
-      high, low = s.split(/,/).map(&:to_i)
-      return (high << 8) + low
+      return s.split(/,/).map(&:to_i).inject { |x, y|
+        (x << 8) + y
+      }
     end
     private :parse_pasv_port
 
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 35138)
+++ test/net/ftp/test_ftp.rb	(revision 35139)
@@ -99,4 +99,12 @@
       ftp.send(:parse229, "229 ) foo bar (")
     end
   end
+
+  def test_parse_pasv_port
+    ftp = Net::FTP.new
+    assert_equal(12, ftp.send(:parse_pasv_port, "12"))
+    assert_equal(3106, ftp.send(:parse_pasv_port, "12,34"))
+    assert_equal(795192, ftp.send(:parse_pasv_port, "12,34,56"))
+    assert_equal(203569230, ftp.send(:parse_pasv_port, "12,34,56,78"))
+  end
 end

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

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