diff --git a/django/utils/text.py b/django/utils/text.py index 6664b18249..02c3f10678 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -24,7 +24,7 @@ capfirst = allow_lazy(capfirst, six.text_type) # Set up regular expressions re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U|re.S) -re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>', re.S) +re_tag = re.compile(r'<(/)?([^ ]+?)(?:(\s*/)| .*?)?>', re.S) def wrap(text, width): diff --git a/tests/regressiontests/utils/text.py b/tests/regressiontests/utils/text.py index 3465282c7f..c9dde6b1b3 100644 --- a/tests/regressiontests/utils/text.py +++ b/tests/regressiontests/utils/text.py @@ -55,22 +55,33 @@ class TestUtilsText(SimpleTestCase): truncator.words(4, '[snip]')) def test_truncate_html_words(self): - truncator = text.Truncator('

The quick brown fox jumped ' - 'over the lazy dog.

') - self.assertEqual('

The quick brown fox jumped over the ' - 'lazy dog.

', truncator.words(10, html=True)) - self.assertEqual('

The quick brown fox...' + truncator = text.Truncator('

The quick brown fox' + ' jumped over the lazy dog.

') + self.assertEqual('

The quick brown fox jumped over' + ' the lazy dog.

', truncator.words(10, html=True)) + self.assertEqual('

The quick brown fox...' '

', truncator.words(4, html=True)) - self.assertEqual('

The quick brown fox....' + self.assertEqual('

The quick brown fox....' '

', truncator.words(4, '....', html=True)) - self.assertEqual('

The quick brown fox' - '

', truncator.words(4, '', html=True)) + self.assertEqual('

The quick brown fox' + '

', truncator.words(4, '', html=True)) + # Test with new line inside tag truncator = text.Truncator('

The quick brown fox jumped over the lazy dog.

') self.assertEqual('

The quick brown...

', truncator.words(3, '...', html=True)) + # Test self-closing tags + truncator = text.Truncator('
The
quick brown fox jumped over' + ' the lazy dog.') + self.assertEqual('
The
quick brown...', + truncator.words(3, '...', html=True )) + truncator = text.Truncator('
The
quick brown fox ' + 'jumped over the lazy dog.') + self.assertEqual('
The
quick brown...', + truncator.words(3, '...', html=True )) + def test_wrap(self): digits = '1234 67 9' self.assertEqual(text.wrap(digits, 100), '1234 67 9')