Check that hosts in parse_url do not contain NULL bytes.

This commit is contained in:
Aldo Cortesi 2013-03-03 15:03:57 +13:00
parent 2897ddfbee
commit cd4ed8530f
2 changed files with 5 additions and 2 deletions

View File

@ -18,7 +18,7 @@ def parse_url(url):
Checks that:
port is an integer
host is a valid IDNA-encoded hostname
host is a valid IDNA-encoded hostname with no null-bytes
path is valid ASCII
"""
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
@ -43,6 +43,8 @@ def parse_url(url):
host.decode("idna")
except ValueError:
return None
if "\0" in host:
return None
try:
path.decode("ascii")
except ValueError:

View File

@ -294,8 +294,9 @@ def test_parse_url():
# Invalid IDNA
assert not http.parse_url("http://\xfafoo")
assert not http.parse_url("http:/\xc6/localhost:56121")
assert not http.parse_url("http://foo\0")
def test_parse_http_basic_auth():