Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12183 -- Made the urlize filter insert the nofollow attribute …

…properly when an http: URL occurs after a mailto: URL. Thanks eronen for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17356 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit aa4e1522968b19499801fe3d73d6b2f3bf3b3acd 1 parent d101ed2
Aymeric Augustin authored January 08, 2012
2  django/utils/html.py
@@ -141,7 +141,6 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
141 141
     trim_url = lambda x, limit=trim_url_limit: limit is not None and (len(x) > limit and ('%s...' % x[:max(0, limit - 3)])) or x
142 142
     safe_input = isinstance(text, SafeData)
143 143
     words = word_split_re.split(force_unicode(text))
144  
-    nofollow_attr = nofollow and ' rel="nofollow"' or ''
145 144
     for i, word in enumerate(words):
146 145
         match = None
147 146
         if '.' in word or '@' in word or ':' in word:
@@ -150,6 +149,7 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
150 149
             lead, middle, trail = match.groups()
151 150
             # Make URL we want to point to.
152 151
             url = None
  152
+            nofollow_attr = ' rel="nofollow"' if nofollow else ''
153 153
             if middle.startswith('http://') or middle.startswith('https://'):
154 154
                 url = smart_urlquote(middle)
155 155
             elif middle.startswith('www.') or ('@' not in middle and \
5  tests/regressiontests/defaultfilters/tests.py
@@ -253,6 +253,11 @@ def test_urlize(self):
253 253
             u'<a href="http://en.wikipedia.org/wiki/Caf%C3%A9" rel="nofollow">'
254 254
             u'http://en.wikipedia.org/wiki/Café</a>')
255 255
 
  256
+        # Check urlize adds nofollow properly - see #12183
  257
+        self.assertEqual(urlize('foo@bar.com or www.bar.com'),
  258
+            u'<a href="mailto:foo@bar.com">foo@bar.com</a> or '
  259
+            u'<a href="http://www.bar.com" rel="nofollow">www.bar.com</a>')
  260
+
256 261
         # Check urlize handles IDN correctly - see #13704
257 262
         self.assertEqual(urlize('http://c✶.ws'),
258 263
             u'<a href="http://xn--c-lgq.ws" rel="nofollow">http://c✶.ws</a>')

0 notes on commit aa4e152

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