diff options
| author | Markus Holtermann <info@markusholtermann.eu> | 2014-10-31 12:04:01 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-10-31 08:06:40 -0400 |
| commit | ed2f96819c9ad6e21e4d397b6418915f5caf522f (patch) | |
| tree | 8fbca93a0edcdc0ac26258ad9bd4a87d0ad9c025 | |
| parent | 98da408964b229ee0b35bb8c4500820e3606aeab (diff) | |
Fixed #23715 -- Prevented urlize from treating a trailing ! as part of an URL
Thanks to 57even for the report.
| -rw-r--r-- | AUTHORS | 2 | ||||
| -rw-r--r-- | django/utils/html.py | 2 | ||||
| -rw-r--r-- | docs/releases/1.8.txt | 4 | ||||
| -rw-r--r-- | tests/defaultfilters/tests.py | 14 |
4 files changed, 18 insertions, 4 deletions
@@ -430,7 +430,7 @@ answer newbie questions, and generally made Django that much better: mark@junklight.com Mark Lavin <markdlavin@gmail.com> Mark Sandstrom <mark@deliciouslynerdy.com> - Markus Holtermann <http://markusholtermann.eu> + Markus Holtermann <https://markusholtermann.eu> martin.glueck@gmail.com Martin Green Martin KosÃr <martin@martinkosir.net> diff --git a/django/utils/html.py b/django/utils/html.py index 115ccbbaaa..2dc16d5d71 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -19,7 +19,7 @@ from .html_parser import HTMLParser, HTMLParseError # Configuration for urlize() function. -TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)', '"', '\''] +TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)', '"', '\'', '!'] WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('<', '>'), ('"', '"'), ('\'', '\'')] # List of possible strings used for bullets in bulleted lists. diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 26dad8d14b..d02672be9a 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -343,6 +343,10 @@ Templates the top-level domain (e.g. ``djangoproject.com/`` and ``djangoproject.com/download/``). +* :tfilter:`urlize` doesn't treat exclamation marks at the end of a domain or + its query string as part of the URL (the URL in e.g. ``'djangoproject.com!`` + is ``djangoproject.com``) + Requests and Responses ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py index 7d135f8caf..bf80ccb313 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -282,8 +282,8 @@ class DefaultFiltersTests(TestCase): '<a href="http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B" rel="nofollow">' 'http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B</a>') self.assertEqual(urlize('www.mystore.com/30%OffCoupons!'), - '<a href="http://www.mystore.com/30%25OffCoupons!" rel="nofollow">' - 'www.mystore.com/30%OffCoupons!</a>') + '<a href="http://www.mystore.com/30%25OffCoupons" rel="nofollow">' + 'www.mystore.com/30%OffCoupons</a>!') self.assertEqual(urlize('http://en.wikipedia.org/wiki/Caf%C3%A9'), '<a href="http://en.wikipedia.org/wiki/Caf%C3%A9" rel="nofollow">' 'http://en.wikipedia.org/wiki/Caf%C3%A9</a>') @@ -370,6 +370,16 @@ class DefaultFiltersTests(TestCase): 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') + # Check urlize correctly handles exclamation marks after TLDs or query string - see #23715 + self.assertEqual(urlize('Go to djangoproject.com! and enjoy.'), + 'Go to <a href="http://djangoproject.com" rel="nofollow">djangoproject.com</a>! and enjoy.') + self.assertEqual(urlize('Search for google.com/?q=! and see.'), + 'Search for <a href="http://google.com/?q=" rel="nofollow">google.com/?q=</a>! and see.') + self.assertEqual(urlize('Search for google.com/?q=dj!`? and see.'), + 'Search for <a href="http://google.com/?q=dj%21%60%3F" rel="nofollow">google.com/?q=dj!`?</a> and see.') + self.assertEqual(urlize('Search for google.com/?q=dj!`?! and see.'), + 'Search for <a href="http://google.com/?q=dj%21%60%3F" rel="nofollow">google.com/?q=dj!`?</a>! and see.') + def test_wordcount(self): self.assertEqual(wordcount(''), 0) self.assertEqual(wordcount('oneword'), 1) |
