Ticket #16395: urlize_malformed_urls-2.diff

File urlize_malformed_urls-2.diff, 2.1 KB (added by Bernhard Essl, 8 years ago)
  • django/utils/html.py

     
    2525html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE)
    2626hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL)
    2727trailing_empty_content_re = re.compile(r'(?:<p>(?:&nbsp;|\s|<br \/>)*?</p>\s*)+\Z')
     28http_begin_re = re.compile(r'^https?://\w')
    2829del x # Temporary variable
    2930
    3031def escape(html):
     
    129130            # Make URL we want to point to.
    130131            url = None
    131132            if middle.startswith('http://') or middle.startswith('https://'):
    132                 url = urlquote(middle, safe='/&=:;#?+*')
     133                if re.match(http_begin_re, middle):
     134                    url = urlquote(middle, safe='/&=:;#?+*')
    133135            elif middle.startswith('www.') or ('@' not in middle and \
    134136                    middle and middle[0] in string.ascii_letters + string.digits and \
    135137                    (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))):
  • tests/regressiontests/defaultfilters/tests.py

     
    217217        self.assertEqual(urlize('https://google.com'),
    218218            u'<a href="https://google.com" rel="nofollow">https://google.com</a>')
    219219
     220        # malformed URIs
     221        self.assertEqual(urlize('http://///www.google.fr/?f=1'),
     222            u'http://///www.google.fr/?f=1')
     223        self.assertEqual(urlize('http://....google.com'),
     224            u'http://....google.com')
     225        self.assertEqual(urlize('https://..google.com'),
     226            u'https://..google.com')
     227
    220228    def test_wordcount(self):
    221229        self.assertEqual(wordcount(''), 0)
    222230        self.assertEqual(wordcount(u'oneword'), 1)
Back to Top