diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-26 14:39:16 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-26 14:39:16 +0000 |
commit | 422c8baeb9639cc51a9f7d458c521f9bd4d98969 (patch) | |
tree | 56d02bdece9016c24e0368c848628bfaa7375aa5 | |
parent | cae1d532f5969d794179f398a6c867d5f402c21c (diff) | |
download | ruby-422c8baeb9639cc51a9f7d458c521f9bd4d98969.tar.gz |
* lib/net/ftp.rb (parse_pasv_port): refactored.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/net/ftp.rb | 5 | ||||
-rw-r--r-- | test/net/ftp/test_ftp.rb | 8 |
3 files changed, 15 insertions, 2 deletions
@@ -1,3 +1,7 @@ +Mon Mar 26 23:19:03 2012 Shugo Maeda <shugo@ruby-lang.org> + + * lib/net/ftp.rb (parse_pasv_port): refactored. + Mon Mar 26 19:49:49 2012 Shugo Maeda <shugo@ruby-lang.org> * test/net/ftp/test_ftp.rb: add the test, which was forgotten in the diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 4fc7fabee3..a92a792b35 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -963,8 +963,9 @@ module Net 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 diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb index 242394063c..209250d675 100644 --- a/test/net/ftp/test_ftp.rb +++ b/test/net/ftp/test_ftp.rb @@ -99,4 +99,12 @@ class FTPTest < Test::Unit::TestCase 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 |