From 6c06adad1dc45631c1c220d7f8fb531a9cf3ed55 Mon Sep 17 00:00:00 2001 From: Giles Richard Greenway Date: Mon, 23 Sep 2013 12:07:26 +0100 Subject: [PATCH] Fixed #20364 -- Changed urlize regexes to include quotation marks as punctation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to EmilStenstrom for raising this, and to Chris PiwoĹ„ski for all of the fixes and most of the tests. --- django/utils/html.py | 4 ++-- tests/defaultfilters/tests.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/django/utils/html.py b/django/utils/html.py index ff3bc600218..75eff0083d2 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -15,8 +15,8 @@ from .html_parser import HTMLParser, HTMLParseError # Configuration for urlize() function. -TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)'] -WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('<', '>')] +TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)', '"', '\''] +WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('<', '>'), ('"', '"'), ('\'', '\'')] # List of possible strings used for bullets in bulleted lists. DOTS = ['·', '*', '\u2022', '•', '•', '•'] diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py index 6f84c14b06d..b1e0f5df96c 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -324,6 +324,24 @@ class DefaultFiltersTests(TestCase): self.assertEqual(urlize('http://[2001:db8:cafe::2]/api/9'), 'http://[2001:db8:cafe::2]/api/9') + # Check urlize correctly include quotation marks in links - #20364 + self.assertEqual(urlize('before "hi@example.com" afterwards'), + u'before "hi@example.com" afterwards') + self.assertEqual(urlize('before hi@example.com" afterwards'), + u'before hi@example.com" afterwards') + self.assertEqual(urlize('before "hi@example.com afterwards'), + u'before "hi@example.com afterwards') + self.assertEqual(urlize('before \'hi@example.com\' afterwards'), + u'before \'hi@example.com\' afterwards') + self.assertEqual(urlize('before hi@example.com\' afterwards'), + u'before hi@example.com\' afterwards') + self.assertEqual(urlize('before \'hi@example.com afterwards'), + u'before \'hi@example.com 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 "hi@example.com", or phone us at +xx.yy') + def test_wordcount(self): self.assertEqual(wordcount(''), 0) self.assertEqual(wordcount('oneword'), 1)