Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Port return type from url.parse() #833
Function url.parse() separates a given URL into individual components, such as the scheme, host, port, and path.
As of now the port part is being returned as
This will make the function more consistent with other libraries, which frequently expect a port parameter in the form of the full-fledged table or a number, but not a string.
The switch will also reduce obscure ambiguities that already exist in the code base. As an example, several scripts contain a code like this:
local function getHostPort(parsed) local host, port = parsed.host, parsed.port -- if no port was found, try to deduce it from the scheme if ( not(port) ) then port = (parsed.scheme == 'https') and 443 port = port or ((parsed.scheme == 'http') and 80) end return host, port end
Such a function will sometimes return the port as a number and other times as a string.
A corresponding patch already exists here. It covers both the change itself and a corresponding clean-up of the consuming code.
The change looks pretty non-controversial but I am cognizant of the fact that it changes behavior of a standard library.
Please let me know if you have any questions or concerns. Otherwise I will commit the change in a few weeks.