Ticket #16395: urlize_malformed_urls.diff
File urlize_malformed_urls.diff, 2.3 KB (added by , 13 years ago) |
---|
-
django/utils/html.py
25 25 html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE) 26 26 hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL) 27 27 trailing_empty_content_re = re.compile(r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\Z') 28 startswith_http_re = re.compile(r'^https?://\w') 28 29 del x # Temporary variable 29 30 30 31 def escape(html): … … 128 129 lead, middle, trail = match.groups() 129 130 # Make URL we want to point to. 130 131 url = None 131 if middle.startswith('http://') or middle.startswith('https://'):132 if re.match(startswith_http_re, middle): 132 133 url = urlquote(middle, safe='/&=:;#?+*') 133 134 elif middle.startswith('www.') or ('@' not in middle and \ 134 135 middle and middle[0] in string.ascii_letters + string.digits and \ 135 (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))): 136 (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com')) and \ 137 (not middle.startswith('http'))): 136 138 url = urlquote('http://%s' % middle, safe='/&=:;#?+*') 137 139 elif '@' in middle and not ':' in middle and simple_email_re.match(middle): 138 140 url = 'mailto:%s' % middle -
tests/regressiontests/defaultfilters/tests.py
217 217 self.assertEqual(urlize('https://google.com'), 218 218 u'<a href="https://google.com" rel="nofollow">https://google.com</a>') 219 219 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 220 226 def test_wordcount(self): 221 227 self.assertEqual(wordcount(''), 0) 222 228 self.assertEqual(wordcount(u'oneword'), 1)