Merge pull request #152 from zeroSteiner/ipv6-with-ports

Correctly handle RFC2732 IPv6 address literals with ports
This commit is contained in:
Mahmoud Hashemi 2019-02-10 22:56:31 -08:00 committed by GitHub
commit 2b3789948a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 10 deletions

View File

@ -898,16 +898,19 @@ def parse_url(url_text):
if hostinfo:
host, sep, port_str = hostinfo.partition(u':')
if sep:
if u']' in port_str:
host = hostinfo # wrong split, was an ipv6
else:
try:
port = int(port_str)
except ValueError:
if port_str: # empty ports ok according to RFC 3986 6.2.3
raise URLParseError('expected integer for port, not %r'
% port_str)
port = None
if host and host[0] == u'[' and u']' in port_str:
host_right, _, port_str = port_str.partition(u']')
host = host + u':' + host_right + u']'
if port_str and port_str[0] == u':':
port_str = port_str[1:]
try:
port = int(port_str)
except ValueError:
if port_str: # empty ports ok according to RFC 3986 6.2.3
raise URLParseError('expected integer for port, not %r'
% port_str)
port = None
family, host = parse_host(host)