From 5da67a084ad6a814c867c3c374f7e869dffac29e Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 19 Jun 2008 12:05:39 +0000 Subject: [PATCH] Fixed #7355 -- Modified urlize utility to handle https:// addresses. Thanks for the report and patch, clint. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7701 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/html.py | 2 +- tests/regressiontests/defaultfilters/tests.py | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/django/utils/html.py b/django/utils/html.py index 17ff78a2b5..07e4f0d3f4 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -99,7 +99,7 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): lead, middle, trail = match.groups() if safe_input: middle = mark_safe(middle) - if middle.startswith('www.') or ('@' not in middle and not middle.startswith('http://') and \ + if middle.startswith('www.') or ('@' not in middle and not (middle.startswith('http://') or middle.startswith('https://')) and \ len(middle) > 0 and middle[0] in string.ascii_letters + string.digits and \ (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))): middle = 'http://%s' % middle diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index 4a8b68a897..62403935d4 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -166,6 +166,27 @@ u'http://31characteruri >>> urlizetrunc(uri, 2) u'...' +# Check normal urlize +>>> urlize('http://google.com') +u'http://google.com' + +>>> urlize('http://google.com/') +u'http://google.com/' + +>>> urlize('www.google.com') +u'http://www.google.com' + +>>> urlize('djangoproject.org') +u'http://djangoproject.org' + +>>> urlize('info@djangoproject.org') +u'info@djangoproject.org' + +# Check urlize with https addresses +>>> urlize('https://google.com') +u'https://google.com' + + >>> wordcount('') 0