Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #20364 -- Changed urlize regexes to include quotation marks as …

…punctation.

Thanks to EmilStenstrom for raising this, and to Chris Piwoński for all of the fixes and most of the tests.
  • Loading branch information...
commit 6c06adad1dc45631c1c220d7f8fb531a9cf3ed55 1 parent 99c87f1
@augeas augeas authored apollo13 committed
Showing with 20 additions and 2 deletions.
  1. +2 −2 django/utils/html.py
  2. +18 −0 tests/defaultfilters/tests.py
View
4 django/utils/html.py
@@ -15,8 +15,8 @@
# Configuration for urlize() function.
-TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)']
-WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('&lt;', '&gt;')]
+TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)', '"', '\'']
+WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('&lt;', '&gt;'), ('"', '"'), ('\'', '\'')]
# List of possible strings used for bullets in bulleted lists.
DOTS = ['&middot;', '*', '\u2022', '&#149;', '&bull;', '&#8226;']
View
18 tests/defaultfilters/tests.py
@@ -324,6 +324,24 @@ def test_urlize(self):
self.assertEqual(urlize('http://[2001:db8:cafe::2]/api/9'),
'<a href="http://[2001:db8:cafe::2]/api/9" rel="nofollow">http://[2001:db8:cafe::2]/api/9</a>')
+ # Check urlize correctly include quotation marks in links - #20364
+ self.assertEqual(urlize('before "hi@example.com" afterwards'),
+ u'before "<a href="mailto:hi@example.com">hi@example.com</a>" afterwards')
+ self.assertEqual(urlize('before hi@example.com" afterwards'),
+ u'before <a href="mailto:hi@example.com">hi@example.com</a>" afterwards')
+ self.assertEqual(urlize('before "hi@example.com afterwards'),
+ u'before "<a href="mailto:hi@example.com">hi@example.com</a> afterwards')
+ self.assertEqual(urlize('before \'hi@example.com\' afterwards'),
+ u'before \'<a href="mailto:hi@example.com">hi@example.com</a>\' afterwards')
+ self.assertEqual(urlize('before hi@example.com\' afterwards'),
+ u'before <a href="mailto:hi@example.com">hi@example.com</a>\' afterwards')
+ self.assertEqual(urlize('before \'hi@example.com afterwards'),
+ u'before \'<a href="mailto:hi@example.com">hi@example.com</a> afterwards')
+
+ # Check urlize copes with commas following URLs in quotes - see #20364
+ self.assertEqual(urlize('Email us at "hi@example.com", or phone us at +xx.yy'),
+ 'Email us at "<a href="mailto:hi@example.com">hi@example.com</a>", or phone us at +xx.yy')
+
def test_wordcount(self):
self.assertEqual(wordcount(''), 0)
self.assertEqual(wordcount('oneword'), 1)
Please sign in to comment.
Something went wrong with that request. Please try again.