From d80703942714155a0d04e4ebbb5deab290e1665a Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 22 Apr 2016 11:24:48 +0300 Subject: Simplified the parsing of the TFTP URI. --- lib/custodian/protocoltest/tftp.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'lib/custodian') 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 -- cgit v1.2.1