Merge pull request #573 from tominsam/master
Fixed #19070: urlize template filter raises exception in some cases
This commit is contained in:
commit
501c7a221c
|
@ -150,6 +150,7 @@ fix_ampersands = allow_lazy(fix_ampersands, six.text_type)
|
||||||
def smart_urlquote(url):
|
def smart_urlquote(url):
|
||||||
"Quotes a URL if it isn't already quoted."
|
"Quotes a URL if it isn't already quoted."
|
||||||
# Handle IDN before quoting.
|
# Handle IDN before quoting.
|
||||||
|
try:
|
||||||
scheme, netloc, path, query, fragment = urlsplit(url)
|
scheme, netloc, path, query, fragment = urlsplit(url)
|
||||||
try:
|
try:
|
||||||
netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
|
netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
|
||||||
|
@ -157,6 +158,9 @@ def smart_urlquote(url):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
url = urlunsplit((scheme, netloc, path, query, fragment))
|
url = urlunsplit((scheme, netloc, path, query, fragment))
|
||||||
|
except ValueError:
|
||||||
|
# invalid IPv6 URL (normally square brackets in hostname part).
|
||||||
|
pass
|
||||||
|
|
||||||
# An URL is considered unquoted if it contains no % characters or
|
# An URL is considered unquoted if it contains no % characters or
|
||||||
# contains a % not followed by two hexadecimal digits. See #9655.
|
# contains a % not followed by two hexadecimal digits. See #9655.
|
||||||
|
|
|
@ -310,6 +310,10 @@ class DefaultFiltersTests(TestCase):
|
||||||
self.assertEqual(urlize('[see www.example.com]'),
|
self.assertEqual(urlize('[see www.example.com]'),
|
||||||
'[see <a href="http://www.example.com" rel="nofollow">www.example.com</a>]' )
|
'[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):
|
def test_wordcount(self):
|
||||||
self.assertEqual(wordcount(''), 0)
|
self.assertEqual(wordcount(''), 0)
|
||||||
|
|
Loading…
Reference in New Issue