Permalink
Browse files

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...
1 parent 4d8a0f8 commit e734477bd739de737d98deef91dfe9f7b8c1c030 @jezdez jezdez committed Feb 4, 2012
Showing with 8 additions and 1 deletion.
  1. +4 −1 django/utils/html.py
  2. +4 −0 tests/regressiontests/defaultfilters/tests.py
@@ -168,7 +168,10 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
url = smart_urlquote('http://%s' % middle)
elif not ':' in middle and simple_email_re.match(middle):
local, domain = middle.rsplit('@', 1)
- domain = domain.encode('idna')
+ try:
+ domain = domain.encode('idna')
+ except UnicodeError:
+ continue
url = 'mailto:%s@%s' % (local, domain)
nofollow_attr = ''
@@ -288,6 +288,10 @@ def test_urlize(self):
self.assertEqual(urlize('usa.gov'),
u'<a href="http://usa.gov" rel="nofollow">usa.gov</a>')
+ # Check urlize don't crash on invalid email with dot-starting domain - see #17592
+ self.assertEqual(urlize('email@.stream.ru'),
+ u'email@.stream.ru')
+
def test_wordcount(self):
self.assertEqual(wordcount(''), 0)
self.assertEqual(wordcount(u'oneword'), 1)

0 comments on commit e734477

Please sign in to comment.