From a93ee5112d42d37187e30aa4edcc1864a79d384a Mon Sep 17 00:00:00 2001 From: LarryBrid Date: Wed, 2 Jul 2014 11:51:51 -0400 Subject: [PATCH] Fixed #22941 - Added support for domain-only links with chars after the TLD to urlize. It now works with something like google.com/foo/bar --- django/utils/html.py | 2 +- docs/ref/templates/builtins.txt | 6 ++++++ docs/releases/1.8.txt | 4 +++- tests/defaultfilters/tests.py | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/django/utils/html.py b/django/utils/html.py index 7c843cf25e..1ab27b4461 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -25,7 +25,7 @@ DOTS = ['·', '*', '\u2022', '•', '•', '•'] unencoded_ampersands_re = re.compile(r'&(?!(\w+|#\d+);)') word_split_re = re.compile(r'(\s+)') simple_url_re = re.compile(r'^https?://\[?\w', re.IGNORECASE) -simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org)$', re.IGNORECASE) +simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org)(.*)$', re.IGNORECASE) simple_email_re = re.compile(r'^\S+@\S+\.\S+$') link_target_attribute_re = re.compile(r'(]*?)target=[^\s>]+') html_gunk_re = re.compile(r'(?:
|<\/i>|<\/b>|<\/em>|<\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE) diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index efa7188990..97860d1463 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -2277,6 +2277,12 @@ It also supports domain-only links ending in one of the original top level domains (``.com``, ``.edu``, ``.gov``, ``.int``, ``.mil``, ``.net``, and ``.org``). For example, ``djangoproject.com`` gets converted. +.. versionchanged:: 1.8 + + Support for domain-only links that include characters after the top-level + domain (e.g. ``djangoproject.com/`` and ``djangoproject.com/download/``) + was added. + Links can have trailing punctuation (periods, commas, close-parens) and leading punctuation (opening parens), and ``urlize`` will still do the right thing. diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 8a736aeb45..3e2790c602 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -207,7 +207,9 @@ Signals Templates ^^^^^^^^^ -* ... +* :tfilter:`urlize` now supports domain-only links that include characters after + the top-level domain (e.g. ``djangoproject.com/`` and + ``djangoproject.com/download/``). Requests and Responses ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py index 7ebef193fa..2e70a1c23b 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -264,6 +264,8 @@ class DefaultFiltersTests(TestCase): '
www.google.com') self.assertEqual(urlize('djangoproject.org'), 'djangoproject.org') + self.assertEqual(urlize('djangoproject.org/'), + 'djangoproject.org/') self.assertEqual(urlize('info@djangoproject.org'), 'info@djangoproject.org')