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

') self.assertEqual(truncatewords_html( '\xc5ngstr\xf6m was here', 1), '\xc5ngstr\xf6m ...') + self.assertEqual(truncatewords_html('Buenos días! ' + '¿Cómo está?', 3), + 'Buenos días! ¿Cómo ...') def test_upper(self): self.assertEqual(upper('Mixed case input'), 'MIXED CASE INPUT') diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py index dd72d26e06..62f1333517 100644 --- a/tests/utils_tests/test_text.py +++ b/tests/utils_tests/test_text.py @@ -82,6 +82,15 @@ class TestUtilsText(SimpleTestCase): self.assertEqual('
The
quick brown...', truncator.words(3, '...', html=True )) + # Test html entities + truncator = text.Truncator('Buenos días!' + ' ¿Cómo está?') + self.assertEqual('Buenos días! ¿Cómo...', + truncator.words(3, '...', html=True)) + truncator = text.Truncator('

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')