parse_url: Handle invalid IPv6 addresses
This commit is contained in:
parent
7b9300743e
commit
b21a7da142
|
@ -21,7 +21,10 @@ def parse_url(url):
|
|||
host is a valid IDNA-encoded hostname with no null-bytes
|
||||
path is valid ASCII
|
||||
"""
|
||||
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
|
||||
try:
|
||||
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
|
||||
except ValueError:
|
||||
return None
|
||||
if not scheme:
|
||||
return None
|
||||
if ':' in netloc:
|
||||
|
|
|
@ -294,11 +294,14 @@ def test_parse_url():
|
|||
|
||||
# Invalid IDNA
|
||||
assert not http.parse_url("http://\xfafoo")
|
||||
# Invalid PATH
|
||||
assert not http.parse_url("http:/\xc6/localhost:56121")
|
||||
# Null byte in host
|
||||
assert not http.parse_url("http://foo\0")
|
||||
# Port out of range
|
||||
assert not http.parse_url("http://foo:999999")
|
||||
|
||||
|
||||
# Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt
|
||||
assert not http.parse_url('http://lo[calhost')
|
||||
|
||||
def test_parse_http_basic_auth():
|
||||
vals = ("basic", "foo", "bar")
|
||||
|
|
Loading…
Reference in New Issue