diff --git a/django/utils/html.py b/django/utils/html.py
index d914234..25605be 100644
a
|
b
|
fix_ampersands = allow_lazy(fix_ampersands, six.text_type)
|
150 | 150 | def smart_urlquote(url): |
151 | 151 | "Quotes a URL if it isn't already quoted." |
152 | 152 | # Handle IDN before quoting. |
153 | | scheme, netloc, path, query, fragment = urlsplit(url) |
154 | 153 | try: |
155 | | netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE |
156 | | except UnicodeError: # invalid domain part |
| 154 | scheme, netloc, path, query, fragment = urlsplit(url) |
| 155 | try: |
| 156 | netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE |
| 157 | except UnicodeError: # invalid domain part |
| 158 | pass |
| 159 | else: |
| 160 | url = urlunsplit((scheme, netloc, path, query, fragment)) |
| 161 | except ValueError: |
| 162 | # invalid IPv6 URL (normally square brackets in hostname part). |
157 | 163 | pass |
158 | | else: |
159 | | url = urlunsplit((scheme, netloc, path, query, fragment)) |
160 | 164 | |
161 | 165 | # An URL is considered unquoted if it contains no % characters or |
162 | 166 | # contains a % not followed by two hexadecimal digits. See #9655. |
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index 52268da..8596f8c 100644
a
|
b
|
class DefaultFiltersTests(TestCase):
|
310 | 310 | self.assertEqual(urlize('[see www.example.com]'), |
311 | 311 | '[see <a href="http://www.example.com" rel="nofollow">www.example.com</a>]' ) |
312 | 312 | |
| 313 | # Check urlize doesn't crash when square bracket is prepended to url (#19070) |
| 314 | self.assertEqual(urlize('see test[at[example.com'), |
| 315 | 'see <a href="http://test[at[example.com" rel="nofollow">test[at[example.com</a>' ) |
| 316 | |
313 | 317 | |
314 | 318 | def test_wordcount(self): |
315 | 319 | self.assertEqual(wordcount(''), 0) |