Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17592 -- Handle URLs starting with a dot when using urlize. Th…

…anks, Claude Paroz.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17435 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e734477bd739de737d98deef91dfe9f7b8c1c030 1 parent 4d8a0f8
Jannis Leidel authored
5  django/utils/html.py
@@ -168,7 +168,10 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
168 168
                 url = smart_urlquote('http://%s' % middle)
169 169
             elif not ':' in middle and simple_email_re.match(middle):
170 170
                 local, domain = middle.rsplit('@', 1)
171  
-                domain = domain.encode('idna')
  171
+                try:
  172
+                    domain = domain.encode('idna')
  173
+                except UnicodeError:
  174
+                    continue
172 175
                 url = 'mailto:%s@%s' % (local, domain)
173 176
                 nofollow_attr = ''
174 177
 
4  tests/regressiontests/defaultfilters/tests.py
@@ -288,6 +288,10 @@ def test_urlize(self):
288 288
         self.assertEqual(urlize('usa.gov'),
289 289
             u'<a href="http://usa.gov" rel="nofollow">usa.gov</a>')
290 290
 
  291
+        # Check urlize don't crash on invalid email with dot-starting domain - see #17592
  292
+        self.assertEqual(urlize('email@.stream.ru'),
  293
+            u'email@.stream.ru')
  294
+
291 295
     def test_wordcount(self):
292 296
         self.assertEqual(wordcount(''), 0)
293 297
         self.assertEqual(wordcount(u'oneword'), 1)

0 notes on commit e734477

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