1
0
mirror of https://github.com/django/django.git synced 2025-10-25 14:46:09 +00:00

Fixed urlize regression with entities in query strings

Refs #22267.
Thanks Shai Berger for spotting the issue and Tim Graham for the
initial patch.
This commit is contained in:
Claude Paroz
2015-03-06 21:56:11 +01:00
parent ceaf31adff
commit ec808e807a
2 changed files with 15 additions and 7 deletions

View File

@@ -282,17 +282,17 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
smart_urlquote. For example:
http://example.com?x=1&amp;y=&lt;2&gt; => http://example.com?x=1&y=<2>
"""
if not safe_input:
return text, text, trail
unescaped = (text + trail).replace(
'&amp;', '&').replace('&lt;', '<').replace(
'&gt;', '>').replace('&quot;', '"').replace('&#39;', "'")
# ';' in trail can be either trailing punctuation or end-of-entity marker
if unescaped.endswith(';'):
return text, unescaped[:-1], trail
else:
if trail and unescaped.endswith(trail):
# Remove trail for unescaped if it was not consumed by unescape
unescaped = unescaped[:-len(trail)]
elif trail == ';':
# Trail was consumed by unescape (as end-of-entity marker), move it to text
text += trail
return text, unescaped, ''
trail = ''
return text, unescaped, trail
words = word_split_re.split(force_text(text))
for i, word in enumerate(words):