Treat empty port in URL the same as absent.

RFC 3986 says that these URLs are equivalent:

http://example.com/
http://example.com:/

url.parse was returning port="" for the latter. Make it instead return
port=nil like the former.
This commit is contained in:
david 2013-02-07 03:06:30 +00:00
parent 1c7c414fbb
commit ac5a479a73

View file

@ -184,7 +184,7 @@ function parse(url, default)
authority = string.gsub(authority,"^([^@]*)@",
function(u) parsed.userinfo = u; return "" end)
authority = string.gsub(authority, ":([0-9]*)$",
function(p) parsed.port = p; return "" end)
function(p) if p ~= "" then parsed.port = p end; return "" end)
if authority ~= "" then parsed.host = authority end
local userinfo = parsed.userinfo
if not userinfo then return parsed end