Code

Ticket #6514: urlize.diff

File urlize.diff, 900 bytes (added by dtulig, 6 years ago)

Escapes all ampersands.

Line 
1diff --git a/django/utils/html.py b/django/utils/html.py
2index 33e2ee3..20ab895 100644
3--- a/django/utils/html.py
4+++ b/django/utils/html.py
5@@ -106,9 +106,10 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
6                         urlquote(middle, safe='/&=:;#?+'),  nofollow_attr,
7                         trim_url(middle))
8             if middle.startswith('http://') or middle.startswith('https://'):
9+                middle = trim_url(middle)
10                 middle = '<a href="%s"%s>%s</a>' % (
11                         urlquote(middle, safe='/&=:;#?+'), nofollow_attr,
12-                        trim_url(middle))
13+                        middle)
14             if '@' in middle and not middle.startswith('www.') and \
15                     not ':' in middle and simple_email_re.match(middle):
16                 middle = '<a href="mailto:%s">%s</a>' % (middle, middle)