Ticket #17592: 17592.diff

File 17592.diff, 1.4 KB (added by Claude Paroz, 12 years ago)

Catch UnicodeError in urlize

  • django/utils/html.py

    diff --git a/django/utils/html.py b/django/utils/html.py
    index c4be281..ba5f753 100644
    a b def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):  
    168168                url = smart_urlquote('http://%s' % middle)
    169169            elif not ':' in middle and simple_email_re.match(middle):
    170170                local, domain = middle.rsplit('@', 1)
    171                 domain = domain.encode('idna')
     171                try:
     172                    domain = domain.encode('idna')
     173                except UnicodeError:
     174                    continue
    172175                url = 'mailto:%s@%s' % (local, domain)
    173176                nofollow_attr = ''
    174177
  • tests/regressiontests/defaultfilters/tests.py

    diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
    index 94e8c43..36f8f58 100644
    a b class DefaultFiltersTests(TestCase):  
    288288        self.assertEqual(urlize('usa.gov'),
    289289            u'<a href="http://usa.gov" rel="nofollow">usa.gov</a>')
    290290
     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
    291295    def test_wordcount(self):
    292296        self.assertEqual(wordcount(''), 0)
    293297        self.assertEqual(wordcount(u'oneword'), 1)
Back to Top