summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-01-08 15:43:32 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-01-08 15:43:32 +0000
commit27508918fbbbfda6f5e3b697bbea6bf2c4a6b8b8 (patch)
treedc9b0ce8a4ad9e95a9b249cfab1e28f07e3b3450 /django
parent40f0ecc56a23d35c2849f8e79276f6d8931412d1 (diff)
Fixed #16395 -- Prevented urlize from highlighting some malformed URLs. Thanks BernhardEssl for the report and initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17358 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/utils/html.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/django/utils/html.py b/django/utils/html.py
index a0ad5f3d00..207620ed86 100644
--- a/django/utils/html.py
+++ b/django/utils/html.py
@@ -23,6 +23,8 @@ word_split_re = re.compile(r'(\s+)')
punctuation_re = re.compile('^(?P<lead>(?:%s)*)(?P<middle>.*?)(?P<trail>(?:%s)*)$' % \
('|'.join([re.escape(x) for x in LEADING_PUNCTUATION]),
'|'.join([re.escape(x) for x in TRAILING_PUNCTUATION])))
+simple_url_re = re.compile(r'^https?://\w')
+simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|net|org)$')
simple_email_re = re.compile(r'^\S+@\S+\.\S+$')
link_target_attribute_re = re.compile(r'(<a [^>]*?)target=[^\s>]+')
html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE)
@@ -150,11 +152,9 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
# Make URL we want to point to.
url = None
nofollow_attr = ' rel="nofollow"' if nofollow else ''
- if middle.startswith('http://') or middle.startswith('https://'):
+ if simple_url_re.match(middle):
url = smart_urlquote(middle)
- elif middle.startswith('www.') or ('@' not in middle and \
- middle and middle[0] in string.ascii_letters + string.digits and \
- (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))):
+ elif simple_url_2_re.match(middle):
url = smart_urlquote('http://%s' % middle)
elif not ':' in middle and simple_email_re.match(middle):
local, domain = middle.rsplit('@', 1)