Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #573 from tominsam/master

Fixed #19070: urlize template filter raises exception in some cases
  • Loading branch information...
commit 501c7a221cfd022b6d0021fd9a54005c5ffc7a23 2 parents b64d304 + 74809fd
@andrewgodwin andrewgodwin authored
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.
View
4 tests/regressiontests/defaultfilters/tests.py
@@ -310,6 +310,10 @@ def test_urlize(self):
self.assertEqual(urlize('[see www.example.com]'),
'[see <a href="http://www.example.com" rel="nofollow">www.example.com</a>]' )
+ # Check urlize doesn't crash when square bracket is prepended to url (#19070)
+ self.assertEqual(urlize('see test[at[example.com'),
+ 'see <a href="http://test[at[example.com" rel="nofollow">test[at[example.com</a>' )
+
def test_wordcount(self):
self.assertEqual(wordcount(''), 0)
Please sign in to comment.
Something went wrong with that request. Please try again.