Skip to content

Commit 2c0348c

Browse files
committed
Found that django's urlize() does not deal well with adjacent parantheses. Replaced it with a filter based on bleach.linkify, which does better.
- Legacy-Id: 14752
1 parent 1df3c71 commit 2c0348c

13 files changed

Lines changed: 51 additions & 22 deletions

ietf/doc/templatetags/ietf_filters.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ def format_history_text(text, trunc_words=25):
370370
def format_snippet(text, trunc_words=25):
371371
# urlize if there aren't already links present
372372
if not 'href=' in text:
373-
# django's urlize() is buggy in at least Django 1.11; use
374-
# bleach.linkify instead
373+
# django's urlize() cannot handle adjacent parentheszised
374+
# expressions, for instance [REF](http://example.com/foo)
375+
# Use bleach.linkify instead
375376
text = bleach.linkify(text)
376377
full = keep_spacing(collapsebr(linebreaksbr(mark_safe(sanitize_html(text)))))
377378
snippet = truncatewords_html(full, trunc_words)
@@ -520,3 +521,9 @@ def zaptmp(s):
520521
def rfcbis(s):
521522
m = re.search('^.*-rfc(\d+)-?bis(-.*)?$', s)
522523
return None if m is None else 'rfc' + m.group(1)
524+
525+
@register.filter
526+
@stringfilter
527+
def urlize(value):
528+
raise RuntimeError("Use linkify from textfilters instead of urlize")
529+

ietf/group/tests_info.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# -*- coding: utf-8 -*-
2+
23
import os
34
import shutil
45
import calendar
56
import datetime
67
import json
78
import StringIO
9+
import bleach
10+
import six
811

912
from pyquery import PyQuery
1013
from tempfile import NamedTemporaryFile
@@ -17,7 +20,6 @@
1720
from django.contrib.auth.models import User
1821

1922
from django.utils.html import escape
20-
from django.template.defaultfilters import urlize
2123

2224
from ietf.community.models import CommunityList
2325
from ietf.community.utils import reset_name_contains_index_for_rule
@@ -1273,7 +1275,7 @@ def test_view_status_update(self):
12731275
response = self.client.get(url)
12741276
self.assertEqual(response.status_code,200)
12751277
q=PyQuery(response.content)
1276-
self.assertTrue(urlize(escape(event.desc) in q('pre')))
1278+
self.assertTrue(bleach.linkify(escape(event.desc)) in six.text_type(q('pre')))
12771279
self.assertFalse(q('a#edit_button'))
12781280
self.client.login(username=chair.person.user.username,password='%s+password'%chair.person.user.username)
12791281
response = self.client.get(url)

ietf/templates/doc/charter/submit.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{% extends "base.html" %}
22
{# Copyright The IETF Trust 2015, All Rights Reserved #}
33
{% load origin %}
4-
54
{% load bootstrap3 %}
5+
{% load textfilters %}
6+
67

78
{% block title %}
89
Charter submission for {{ group.acronym }} {{ group.type.name }}
@@ -72,10 +73,10 @@ <h1>Charter submission</h1>
7273
<tbody class="meta">
7374
<tr>
7475
<th>Mailing list</th>
75-
<th>Address</th><td>{{ group.list_email|urlize }}</td>
76+
<th>Address</th><td>{{ group.list_email|linkify }}</td>
7677
</tr>
77-
<tr><td></td><th>To subscribe</th><td>{{ group.list_subscribe|urlize }}</td></tr>
78-
<tr><td></td><th>Archive</th><td>{{ group.list_archive|urlize }}</td></tr>
78+
<tr><td></td><th>To subscribe</th><td>{{ group.list_subscribe|linkify }}</td></tr>
79+
<tr><td></td><th>Archive</th><td>{{ group.list_archive|linkify }}</td></tr>
7980
</tbody>
8081
{% endif %}
8182
</table>

ietf/templates/doc/document_ballot_content.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{# Copyright The IETF Trust 2015, All Rights Reserved #}{% load origin %}{% origin %}
22
{% load ietf_filters %}
3+
{% load textfilters %}
4+
35
<div class="row">
46
<div class="col-md-2 hidden-sm hidden-xs">
57

@@ -91,7 +93,7 @@ <h4 class="anchor-target" id="{{ p.ad.plain_name|slugify }}">
9193
<div class="panel-heading">
9294
<h5 class="panel-title"><b>{{ p.pos.name }}</b> ({{ p.discuss_time|date:"Y-m-d" }}{% if not p.for_current_revision %} for -{{ p.get_dochistory.rev}}{% endif %})</h5>
9395
</div>
94-
<div class="panel-body"><pre class="ballot pasted">{{ p.discuss|escape|urlize }}</pre></div>
96+
<div class="panel-body"><pre class="ballot pasted">{{ p.discuss|escape|linkify }}</pre></div>
9597
</div>
9698
{% endif %}
9799

@@ -100,7 +102,7 @@ <h5 class="panel-title"><b>{{ p.pos.name }}</b> ({{ p.discuss_time|date:"Y-m-d"
100102
<div class="panel-heading">
101103
<h5 class="panel-title"><b>Comment</b> ({{ p.comment_time|date:"Y-m-d" }}{% if not p.for_current_revision %} for -{{ p.get_dochistory.rev}}{% endif %})</h5>
102104
</div>
103-
<div class="panel-body"><pre class="ballot pasted">{{ p.comment|escape|urlize }}</pre></div>
105+
<div class="panel-body"><pre class="ballot pasted">{{ p.comment|escape|linkify }}</pre></div>
104106
</div>
105107
{% endif %}
106108
{% endfor %}

ietf/templates/doc/document_review.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{% load origin %}
44
{% load staticfiles %}
55
{% load ietf_filters %}
6+
{% load textfilters %}
67

78
{% block title %}{{ doc.title }}{% endblock %}
89

@@ -54,6 +55,6 @@
5455
<h2>{{ doc.type.name }}<br><small>{{ doc.name }}</small></h2>
5556

5657
{% if doc.rev and content != None %}
57-
<pre class="pasted">{{ content|urlize|safe|sanitize_html|safe }}</pre>
58+
<pre class="pasted">{{ content|linkify|safe|sanitize_html|safe }}</pre>
5859
{% endif %}
5960
{% endblock %}

ietf/templates/doc/document_writeup.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{% load origin %}
44

55
{% load ietf_filters %}
6+
{% load textfilters %}
67

78
{% block title %}Writeups for {{ doc.name }}-{{ doc.rev }}{% endblock %}
89

@@ -20,7 +21,7 @@ <h2>
2021

2122
{% for name, text, url in writeups %}
2223
{% if text %}
23-
<pre>{{ text|urlize }}</pre>
24+
<pre>{{ text|linkify }}</pre>
2425
{% endif %}
2526

2627
<p>

ietf/templates/doc/drafts_in_iesg_process.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% extends "base.html" %}
22
{# Copyright The IETF Trust 2015, All Rights Reserved #}
33
{% load origin %}
4-
54
{% load ietf_filters staticfiles %}
5+
{% load textfilters %}
66

77
{% block pagehead %}
88
{% if last_call_only %}
@@ -47,7 +47,7 @@ <h1>{{ title }}</h1>
4747
<a href="{% url "ietf.doc.views_doc.document_main" doc.name %}">{{ doc.name }}</a>
4848
<br><b>{{ doc.title }}</b>
4949
{% if doc.note %}
50-
<br><i>Note: {{ doc.note|linebreaksbr|urlize }}</i>
50+
<br><i>Note: {{ doc.note|linebreaksbr|linkify }}</i>
5151
{% endif %}
5252
</td>
5353
<td>{{ doc.intended_std_level.name }}</td>

ietf/templates/doc/shepherd_writeup.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{# Copyright The IETF Trust 2015, All Rights Reserved #}
33
{% load origin %}
44
{% load ietf_filters %}
5+
{% load textfilters %}
56

67
{% block title %}
78
Shepherd writeup for {{ doc.canonical_name }}-{{ doc.rev }}
@@ -11,7 +12,7 @@
1112
{% origin %}
1213
<h1>Shepherd writeup<br><small>{{ doc.canonical_name }}-{{ doc.rev }}</small></h1>
1314

14-
<pre class="pasted">{{writeup|escape|urlize}}</pre>
15+
<pre class="pasted">{{writeup|escape|linkify}}</pre>
1516

1617
{% if can_edit %}
1718
<a class="btn btn-primary" href="{% url 'ietf.doc.views_draft.edit_shepherd_writeup' name=doc.name %}">Edit</a>

ietf/templates/group/all_status.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
{% load staticfiles %}
55
{% load bootstrap3 %}
66
{% load ietf_filters %}
7+
{% load textfilters %}
8+
79

810
{% block title %}
911
Status updates
@@ -27,7 +29,7 @@ <h2> {{area_item.grouper.acronym|upper}}
2729
<span class="label label-success">{{ rpt.group.state.slug|upper }}</span>
2830
{% endif %}
2931
<br> {{rpt.time|date:"Y-m-d"}}</td>
30-
<td><pre class="pasted">{{ rpt.desc|default:"(none)"|escape|urlize }}</pre></td>
32+
<td><pre class="pasted">{{ rpt.desc|default:"(none)"|escape|linkify }}</pre></td>
3133
</tr>
3234
{% endfor %}
3335
</table>
@@ -42,7 +44,7 @@ <h2> IRTF <small>Internet Research Task Force</small> </h2>
4244
<span class="label label-success">{{ rpt.group.state.slug|upper }}</span>
4345
{% endif %}
4446
<br> {{rpt.time|date:"Y-m-d"}}</td>
45-
<td><pre class="pasted">{{ rpt.desc|default:"(none)"|escape|urlize }}</pre></td>
47+
<td><pre class="pasted">{{ rpt.desc|default:"(none)"|escape|linkify }}</pre></td>
4648
</tr>
4749
{% endfor %}
4850
</table>

ietf/templates/group/group_about.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{% load origin %}
44
{% load ietf_filters %}
55
{% load markup_tags %}
6+
{% load textfilters %}
67

78
{% block group_content %}
89
{% origin %}
@@ -176,7 +177,7 @@
176177
<a class="btn btn-default btn-xs" href="{% url 'ietf.group.views.edit' acronym=group.acronym field='list_email' %}">Edit</a>
177178
{% endif %}
178179
</td>
179-
<td>{{ group.list_email|urlize }}</td>
180+
<td>{{ group.list_email|linkify }}</td>
180181
</tr>
181182
<tr>
182183
<td></td>
@@ -186,7 +187,7 @@
186187
<a class="btn btn-default btn-xs" href="{% url 'ietf.group.views.edit' acronym=group.acronym field='list_subscribe' %}">Edit</a>
187188
{% endif %}
188189
</td>
189-
<td>{{ group.list_subscribe|urlize }}</td>
190+
<td>{{ group.list_subscribe|linkify }}</td>
190191
</tr>
191192
<tr>
192193
<td></td>
@@ -196,7 +197,7 @@
196197
<a class="btn btn-default btn-xs" href="{% url 'ietf.group.views.edit' acronym=group.acronym field='list_archive' %}">Edit</a>
197198
{% endif %}
198199
</td>
199-
<td>{{ group.list_archive|urlize }}</td>
200+
<td>{{ group.list_archive|linkify }}</td>
200201
</tr>
201202
</tbody>
202203
{% endif %}

0 commit comments

Comments
 (0)