diff --git a/AUTHORS b/AUTHORS index 6e33ff44e29..7fb69509960 100644 --- a/AUTHORS +++ b/AUTHORS @@ -430,7 +430,7 @@ answer newbie questions, and generally made Django that much better: mark@junklight.com Mark Lavin Mark Sandstrom - Markus Holtermann + Markus Holtermann martin.glueck@gmail.com Martin Green Martin Kosír diff --git a/django/utils/html.py b/django/utils/html.py index 115ccbbaaa4..2dc16d5d71e 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 26dad8d14b9..d02672be9ab 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 7d135f8cafe..bf80ccb3136 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -282,8 +282,8 @@ class DefaultFiltersTests(TestCase): '' 'http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B') self.assertEqual(urlize('www.mystore.com/30%OffCoupons!'), - '' - 'www.mystore.com/30%OffCoupons!') + '' + 'www.mystore.com/30%OffCoupons!') self.assertEqual(urlize('http://en.wikipedia.org/wiki/Caf%C3%A9'), '' 'http://en.wikipedia.org/wiki/Caf%C3%A9') @@ -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 "hi@example.com", 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 djangoproject.com! and enjoy.') + self.assertEqual(urlize('Search for google.com/?q=! and see.'), + 'Search for google.com/?q=! and see.') + self.assertEqual(urlize('Search for google.com/?q=dj!`? and see.'), + 'Search for google.com/?q=dj!`? and see.') + self.assertEqual(urlize('Search for google.com/?q=dj!`?! and see.'), + 'Search for google.com/?q=dj!`?! and see.') + def test_wordcount(self): self.assertEqual(wordcount(''), 0) self.assertEqual(wordcount('oneword'), 1)