summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Insam <tom@movieos.org>2012-12-03 12:13:24 +0000
committerTom Insam <tom@movieos.org>2012-12-03 12:13:24 +0000
commit74809fdcc75c400e7d2eac4fa1b0f4113f9f395b (patch)
tree8ced8b595df2d0b22f769b16117e6fef392a37a9
parent161cafb6f695df5d886ed94ab2489a420cd97ecc (diff)
cope with unsplittable urls in smarl_urlquote.
-rw-r--r--django/utils/html.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/django/utils/html.py b/django/utils/html.py
index d914234d60..25605bea04 100644
--- a/django/utils/html.py
+++ b/django/utils/html.py
@@ -150,13 +150,17 @@ fix_ampersands = allow_lazy(fix_ampersands, six.text_type)
def smart_urlquote(url):
"Quotes a URL if it isn't already quoted."
# Handle IDN before quoting.
- scheme, netloc, path, query, fragment = urlsplit(url)
try:
- netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
- except UnicodeError: # invalid domain part
+ scheme, netloc, path, query, fragment = urlsplit(url)
+ try:
+ netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
+ except UnicodeError: # invalid domain part
+ pass
+ else:
+ url = urlunsplit((scheme, netloc, path, query, fragment))
+ except ValueError:
+ # invalid IPv6 URL (normally square brackets in hostname part).
pass
- else:
- url = urlunsplit((scheme, netloc, path, query, fragment))
# An URL is considered unquoted if it contains no % characters or
# contains a % not followed by two hexadecimal digits. See #9655.