Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16656 -- Changed the urlize filter to accept more top-level do…

…mains.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17359 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 05a3ecbf9637b8873dc0eb6913a94117a90c9bc0 1 parent 2750891
Aymeric Augustin authored January 08, 2012
11  django/utils/html.py
@@ -24,7 +24,7 @@
24 24
     ('|'.join([re.escape(x) for x in LEADING_PUNCTUATION]),
25 25
     '|'.join([re.escape(x) for x in TRAILING_PUNCTUATION])))
26 26
 simple_url_re = re.compile(r'^https?://\w')
27  
-simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|net|org)$')
  27
+simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org|[a-z]{2})$')
28 28
 simple_email_re = re.compile(r'^\S+@\S+\.\S+$')
29 29
 link_target_attribute_re = re.compile(r'(<a [^>]*?)target=[^\s>]+')
30 30
 html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE)
@@ -127,10 +127,11 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
127 127
     """
128 128
     Converts any URLs in text into clickable links.
129 129
 
130  
-    Works on http://, https://, www. links and links ending in .org, .net or
131  
-    .com. Links can have trailing punctuation (periods, commas, close-parens)
132  
-    and leading punctuation (opening parens) and it'll still do the right
133  
-    thing.
  130
+    Works on http://, https://, www. links, and also on links ending in one of
  131
+    the original seven gTLDs (.com, .edu, .gov, .int, .mil, .net, and .org) or
  132
+    a two-letter ccTLD. Links can have trailing punctuation (periods, commas,
  133
+    close-parens) and leading punctuation (opening parens) and it'll still do
  134
+    the right thing.
134 135
 
135 136
     If trim_url_limit is not None, the URLs in link text longer than this limit
136 137
     will truncated to trim_url_limit-3 characters and appended with an elipsis.
19  docs/ref/templates/builtins.txt
@@ -2226,13 +2226,20 @@ urlize
2226 2226
 
2227 2227
 Converts URLs in text into clickable links.
2228 2228
 
2229  
-Works on links prefixed with ``http://``, ``https://``, or ``www.``. For
2230  
-example, ``http://goo.gl/aia1t`` will get converted but ``goo.gl/aia1t``
2231  
-won't.
  2229
+This template tag works on several kinds of links:
2232 2230
 
2233  
-Also works on domain-only links ending in one of the common ``.com``, ``.net``,
2234  
-or ``.org`` top level domains. For example, ``djangoproject.com`` will still
2235  
-get converted.
  2231
+- links prefixed with ``http://``, ``https://``, or ``www.``. For example,
  2232
+  ``http://goo.gl/aia1t`` will get converted but ``goo.gl/aia1t`` won't.
  2233
+- domain-only links ending in one of the original top level domains
  2234
+  (``.com``, ``.edu``, ``.gov``, ``.int``, ``.mil``, ``.net``, and
  2235
+  ``.org``). For example, ``djangoproject.com`` also gets converted.
  2236
+- domain-only links ending in a dot followed by two letters. This covers
  2237
+  most country codes. For example, ``djangocon.eu`` still gets converted.
  2238
+
  2239
+.. versionchanged:: 1.4
  2240
+
  2241
+Until Django 1.4, only the ``.com``, ``.net`` and ``.org`` suffixes were
  2242
+supported for domain-only links.
2236 2243
 
2237 2244
 Links can have trailing punctuation (periods, commas, close-parens) and leading
2238 2245
 punctuation (opening parens) and ``urlize`` will still do the right thing.
6  tests/regressiontests/defaultfilters/tests.py
@@ -276,6 +276,12 @@ def test_urlize(self):
276 276
         self.assertEqual(urlize('http://@foo.com'),
277 277
             u'http://@foo.com')
278 278
 
  279
+        # Check urlize accepts more TLDs - see #16656
  280
+        self.assertEqual(urlize('usa.gov'),
  281
+            u'<a href="http://usa.gov" rel="nofollow">usa.gov</a>')
  282
+        self.assertEqual(urlize('europa.eu'),
  283
+            u'<a href="http://europa.eu" rel="nofollow">europa.eu</a>')
  284
+
279 285
     def test_wordcount(self):
280 286
         self.assertEqual(wordcount(''), 0)
281 287
         self.assertEqual(wordcount(u'oneword'), 1)

0 notes on commit 05a3ecb

Please sign in to comment.
Something went wrong with that request. Please try again.