Don't die if a url fails to parse.

This commit is contained in:
Neil Williams
2011-08-24 19:36:07 -07:00
parent 791a89043e
commit e88adc7e5b

View File

@@ -275,11 +275,14 @@ def sanitize_url(url, require_scheme = False):
if url.lower() == 'self':
return url
u = urlparse(url)
# first pass: make sure a scheme has been specified
if not require_scheme and not u.scheme:
url = 'http://' + url
try:
u = urlparse(url)
# first pass: make sure a scheme has been specified
if not require_scheme and not u.scheme:
url = 'http://' + url
u = urlparse(url)
except ValueError:
return
if u.scheme and u.scheme in valid_schemes:
# if there is a scheme and no hostname, it is a bad url.