Ticket #16395: urlize_malformed_urls-2.diff
File urlize_malformed_urls-2.diff, 2.1 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 http_begin_re = re.compile(r'^https?://\w') 28 29 del x # Temporary variable 29 30 30 31 def escape(html): … … 129 130 # Make URL we want to point to. 130 131 url = None 131 132 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='/&=:;#?+*') 133 135 elif middle.startswith('www.') or ('@' not in middle and \ 134 136 middle and middle[0] in string.ascii_letters + string.digits and \ 135 137 (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))): -
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 self.assertEqual(urlize('https://..google.com'), 226 u'https://..google.com') 227 220 228 def test_wordcount(self): 221 229 self.assertEqual(wordcount(''), 0) 222 230 self.assertEqual(wordcount(u'oneword'), 1)