diff --git a/django/utils/text.py b/django/utils/text.py index 93c33b3351..50713193dd 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -22,7 +22,7 @@ capfirst = lambda x: x and force_text(x)[0].upper() + force_text(x)[1:] capfirst = allow_lazy(capfirst, six.text_type) # Set up regular expressions -re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U|re.S) +re_words = re.compile(r'<.*?>|((?:\w[-\w]*|&.*?;)+)', re.U|re.S) re_tag = re.compile(r'<(/)?([^ ]+?)(?:(\s*/)| .*?)?>', re.S) diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py index b752299fcd..dcd6bb7364 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -184,6 +184,9 @@ class DefaultFiltersTests(TestCase): '
one two - three
four five
I <3 python, what about you?
') + self.assertEqual('I <3 python...
', + truncator.words(3, '...', html=True)) + def test_wrap(self): digits = '1234 67 9' self.assertEqual(text.wrap(digits, 100), '1234 67 9')