Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #10931 -- Made `Truncator` handle newlines properly. Thanks to …

…gsong and Claude Paroz.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17329 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1572a3d4b2dd4afd004765ba73a2c38b311b65ee 1 parent 6fa62b8
@jphalip jphalip authored
Showing with 7 additions and 2 deletions.
  1. +2 −2 django/utils/text.py
  2. +5 −0 tests/regressiontests/utils/text.py
View
4 django/utils/text.py
@@ -18,8 +18,8 @@
capfirst = allow_lazy(capfirst, unicode)
# Set up regular expressions
-re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U)
-re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>')
+re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U|re.S)
+re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>', re.S)
def wrap(text, width):
View
5 tests/regressiontests/utils/text.py
@@ -62,6 +62,11 @@ def test_truncate_html_words(self):
'</strong></p>', truncator.words(4, '....', html=True))
self.assertEqual(u'<p><strong><em>The quick brown fox</em></strong>'
'</p>', truncator.words(4, '', html=True))
+ # Test with new line inside tag
+ truncator = text.Truncator('<p>The quick <a href="xyz.html"\n'
+ 'id="mylink">brown fox</a> jumped over the lazy dog.</p>')
+ self.assertEqual(u'<p>The quick <a href="xyz.html"\n'
+ 'id="mylink">brown...</a></p>', truncator.words(3, '...', html=True))
def test_old_truncate_words(self):
self.assertEqual(u'The quick brown fox jumped over the lazy dog.',
Please sign in to comment.
Something went wrong with that request. Please try again.