Permalink
Browse files

cope with unsplittable urls in smarl_urlquote.

  • Loading branch information...
1 parent 161cafb commit 74809fdcc75c400e7d2eac4fa1b0f4113f9f395b @tominsam tominsam committed Dec 3, 2012
Showing with 9 additions and 5 deletions.
  1. +9 −5 django/utils/html.py
View
14 django/utils/html.py
@@ -150,13 +150,17 @@ def fix_ampersands(value):
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.

0 comments on commit 74809fd

Please sign in to comment.