Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Julien Phalip authored January 02, 2012
4  django/utils/text.py
@@ -18,8 +18,8 @@
18 18
 capfirst = allow_lazy(capfirst, unicode)
19 19
 
20 20
 # Set up regular expressions
21  
-re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U)
22  
-re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>')
  21
+re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U|re.S)
  22
+re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>', re.S)
23 23
 
24 24
 
25 25
 def wrap(text, width):
5  tests/regressiontests/utils/text.py
@@ -62,6 +62,11 @@ def test_truncate_html_words(self):
62 62
             '</strong></p>', truncator.words(4, '....', html=True))
63 63
         self.assertEqual(u'<p><strong><em>The quick brown fox</em></strong>'
64 64
             '</p>', truncator.words(4, '', html=True))
  65
+        # Test with new line inside tag
  66
+        truncator = text.Truncator('<p>The quick <a href="xyz.html"\n'
  67
+            'id="mylink">brown fox</a> jumped over the lazy dog.</p>')
  68
+        self.assertEqual(u'<p>The quick <a href="xyz.html"\n'
  69
+            'id="mylink">brown...</a></p>', truncator.words(3, '...', html=True))
65 70
 
66 71
     def test_old_truncate_words(self):
67 72
         self.assertEqual(u'The quick brown fox jumped over the lazy dog.',

0 notes on commit 1572a3d

Please sign in to comment.
Something went wrong with that request. Please try again.