Code

Ticket #19070: 19070-1.diff

File 19070-1.diff, 1.6 KB (added by claudep, 21 months ago)

Fixing the square bracket issue

Line 
1diff --git a/django/utils/html.py b/django/utils/html.py
2index cc83729..9816b9a 100644
3--- a/django/utils/html.py
4+++ b/django/utils/html.py
5@@ -18,7 +18,7 @@ from django.utils.text import normalize_newlines
6 
7 # Configuration for urlize() function.
8 TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)']
9-WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('&lt;', '&gt;')]
10+WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('&lt;', '&gt;')]
11 
12 # List of possible strings used for bullets in bulleted lists.
13 DOTS = ['&middot;', '*', '\u2022', '&#149;', '&bull;', '&#8226;']
14diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
15index bdf3c86..8e800ef 100644
16--- a/tests/regressiontests/defaultfilters/tests.py
17+++ b/tests/regressiontests/defaultfilters/tests.py
18@@ -301,7 +301,12 @@ class DefaultFiltersTests(TestCase):
19 
20         # Check urlize trims trailing period when followed by parenthesis - see #18644
21         self.assertEqual(urlize('(Go to http://www.example.com/foo.)'),
22-                         '(Go to <a href="http://www.example.com/foo" rel="nofollow">http://www.example.com/foo</a>.)')
23+            '(Go to <a href="http://www.example.com/foo" rel="nofollow">http://www.example.com/foo</a>.)')
24+
25+        # Check urlize doesn't crash when square bracket is appended to url (#19070)
26+        self.assertEqual(urlize('[see www.example.com]'),
27+            '[see <a href="http://www.example.com" rel="nofollow">www.example.com</a>]' )
28+
29 
30     def test_wordcount(self):
31         self.assertEqual(wordcount(''), 0)