diff options
author | Steve Kemp <steve@steve.org.uk> | 2016-04-22 11:24:48 +0300 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2016-04-22 11:24:48 +0300 |
commit | d80703942714155a0d04e4ebbb5deab290e1665a (patch) | |
tree | a0d0f1f5bdbd5a936f7c9676edfe608e3e3f808f /lib | |
parent | fd026c723145db12a88c91125efa37a02e211da4 (diff) |
Simplified the parsing of the TFTP URI.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/custodian/protocoltest/tftp.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/custodian/protocoltest/tftp.rb b/lib/custodian/protocoltest/tftp.rb index 7a6abe3..596a204 100644 --- a/lib/custodian/protocoltest/tftp.rb +++ b/lib/custodian/protocoltest/tftp.rb @@ -2,6 +2,8 @@ require 'custodian/settings' require 'custodian/testfactory' require 'custodian/util/tftp' +require 'uri' + # # The TFTP-protocol test @@ -52,7 +54,7 @@ module Custodian # # Save the URL # - url = line.split(/\s+/)[0] + url = line.split(/\s+/)[0] # # Ensure we've got a TFTP url. @@ -62,14 +64,19 @@ module Custodian end # - # Extract host, port and file from URL + # Parse the URL which should have a host + path, and optional port # - if line =~ /^tftp:\/\/([^\/]+)\/([^\s]*)/ - @host = $1.split(':')[0] - @file = $2.dup - p = $1.split(':')[1] - @port = (p && p.to_i > 0) ? p.to_i : 69 - end + u = URI.parse(url) + + # + # Record the values. + # + @host = u.host + @file = u.path + + # Port might not be specified, if it is missing then default to 69. + @port = u.port || "69" + @port = @port.to_i # # Ensure there is a file to fetch |