Skip to content

Commit a683548

Browse files
committed
Add and use bleach_tags filter and fix tests
Add bleach and upgraded html5lib submodules Replace all instances of strip_tags|safe with bleach_tags|safe Fix tests
1 parent 016fc02 commit a683548

File tree

11 files changed

+44
-28
lines changed

11 files changed

+44
-28
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@
6464
[submodule "vendor-local/src/django"]
6565
path = vendor-local/src/django
6666
url = git://github.com/django/django.git
67+
[submodule "vendor-local/src/bleach"]
68+
path = vendor-local/src/bleach
69+
url = https://github.com/jsocol/bleach.git
70+
[submodule "vendor-local/src/html5lib"]
71+
path = vendor-local/src/html5lib
72+
url = https://github.com/html5lib/html5lib-python

bedrock/legal/templates/legal/emails/fraud-report.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ A new violating website report has been submitted with the following information
1010
{{ input_product }}
1111

1212
+ Specific product
13-
{{ input_specific_product|strip_tags|safe }}
13+
{{ input_specific_product|bleach_tags|safe }}
1414

1515
+ Other details...
16-
{{ input_details|strip_tags|safe }}
16+
{{ input_details|bleach_tags|safe }}
1717

1818
+ Attachments...
19-
{{ input_attachment_desc|strip_tags|safe }}
19+
{{ input_attachment_desc|bleach_tags|safe }}
2020

2121
+ Email
2222
{{ input_email }}

bedrock/legal/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: utf8 -*-
1+
# -*- coding: utf-8 -*-
22
# This Source Code Form is subject to the terms of the Mozilla Public
33
# License, v. 2.0. If a copy of the MPL was not distributed with this
44
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -228,7 +228,7 @@ def test_emails_not_escaped(self):
228228
"""
229229

230230
STRING1 = u"<em>J'adore Citröns</em> & <Piñatas> so there"
231-
EXPECTED1 = u"J'adore Citröns & <Piñatas> so there"
231+
EXPECTED1 = u"J'adore Citröns & so there"
232232

233233
STRING2 = u"<em>J'adore Piñatas</em> & <fromage> so here"
234234
EXPECTED2 = u"J'adore Piñatas & so here"

bedrock/mozorg/helpers/misc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.conf import settings
66
from django.template.defaultfilters import slugify as django_slugify
77

8+
import bleach
89
import jingo
910
import jinja2
1011
from funfactory.settings_base import path as base_path
@@ -517,3 +518,8 @@ def slugify(text):
517518
trailing whitespace.
518519
"""
519520
return django_slugify(text)
521+
522+
523+
@jingo.register.filter
524+
def bleach_tags(text):
525+
return bleach.clean(text, tags=[], strip=True).replace('&amp;', '&')
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Email: {{ email }}
22
Area of Interest: {{ interest }}
33
Language: {{ request.locale }}
4-
Comment: {{ comments|strip_tags|safe }}
4+
Comment: {{ comments|bleach_tags|safe }}

bedrock/mozorg/tests/test_views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def test_emails_not_escaped(self):
424424
Tags are still stripped, though.
425425
"""
426426
STRING = u"<strong>J'adore Citröns</strong> & <Piñatas> so there"
427-
EXPECTED = u"J'adore Citröns & <Piñatas> so there"
427+
EXPECTED = u"J'adore Citröns & so there"
428428
self.data.update(comments=STRING)
429429
self.client.post(self.url_en, self.data)
430430
eq_(len(mail.outbox), 2)
@@ -593,7 +593,7 @@ def test_emails_not_escaped(self):
593593
Tags are still stripped, though.
594594
"""
595595
STRING = u"<em>J'adore Citröns</em> & <Piñatas> so there"
596-
EXPECTED = u"J'adore Citröns & <Piñatas> so there"
596+
EXPECTED = u"J'adore Citröns & so there"
597597
self.data.update(comments=STRING)
598598
self.client.post(self.url_en, self.data)
599599
eq_(len(mail.outbox), 2)

bedrock/press/templates/press/emails/speaker-request.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
A new speaker request form has been submitted with the following information:
22

33
+ Event Name
4-
{{ sr_event_name|strip_tags|safe }}
4+
{{ sr_event_name|bleach_tags|safe }}
55

66
+ Event URL
77
{{ sr_event_url }}
@@ -15,29 +15,29 @@ Guest Speaker
1515

1616
{% if sr_guest_speaker1 %}
1717
+ Choice 1
18-
{{ sr_guest_speaker1|strip_tags|safe }}
18+
{{ sr_guest_speaker1|bleach_tags|safe }}
1919
{% endif %}
2020
{% if sr_guest_speaker2 %}
2121

2222
+ Choice 2
23-
{{ sr_guest_speaker2|strip_tags|safe }}
23+
{{ sr_guest_speaker2|bleach_tags|safe }}
2424
{% endif %}
2525

2626
{% endif %}
2727
------------------------------------
2828
Contact Information
2929

3030
+ Name
31-
{{ sr_contact_name|strip_tags|safe }}
31+
{{ sr_contact_name|bleach_tags|safe }}
3232
{% if sr_contact_title %}
3333

3434
+ Title
35-
{{ sr_contact_title|strip_tags|safe }}
35+
{{ sr_contact_title|bleach_tags|safe }}
3636
{% endif %}
3737
{% if sr_contact_company %}
3838

3939
+ Company
40-
{{ sr_contact_company|strip_tags|safe }}
40+
{{ sr_contact_company|bleach_tags|safe }}
4141
{% endif %}
4242
{% if sr_contact_phone %}
4343

@@ -58,22 +58,22 @@ Event Details
5858

5959
{% if sr_event_venue %}
6060
+ Venue
61-
{{ sr_event_venue|strip_tags|safe }}
61+
{{ sr_event_venue|bleach_tags|safe }}
6262
{% endif %}
6363
{% if sr_event_theme %}
6464

6565
+ Theme
66-
{{ sr_event_theme|strip_tags|safe }}
66+
{{ sr_event_theme|bleach_tags|safe }}
6767
{% endif %}
6868
{% if sr_event_goal %}
6969

7070
+ Goal
71-
{{ sr_event_goal|strip_tags|safe }}
71+
{{ sr_event_goal|bleach_tags|safe }}
7272
{% endif %}
7373
{% if sr_event_format %}
7474

7575
+ Format
76-
{{ sr_event_format|strip_tags|safe }}
76+
{{ sr_event_format|bleach_tags|safe }}
7777
{% endif %}
7878
{% if sr_event_audience_size %}
7979

@@ -83,32 +83,32 @@ Event Details
8383
{% if sr_event_audience_demographics %}
8484

8585
+ Audience Demographics
86-
{{ sr_event_audience_demographics|strip_tags|safe }}
86+
{{ sr_event_audience_demographics|bleach_tags|safe }}
8787
{% endif %}
8888
{% if sr_event_speakers_confirmed %}
8989

9090
+ Confirmed Speakers
91-
{{ sr_event_speakers_confirmed|strip_tags|safe }}
91+
{{ sr_event_speakers_confirmed|bleach_tags|safe }}
9292
{% endif %}
9393
{% if sr_event_speakers_invited %}
9494

9595
+ Invited Speakers
96-
{{ sr_event_speakers_invited|strip_tags|safe }}
96+
{{ sr_event_speakers_invited|bleach_tags|safe }}
9797
{% endif %}
9898
{% if sr_event_speakers_past %}
9999

100100
+ Past Speakers
101-
{{ sr_event_speakers_past|strip_tags|safe }}
101+
{{ sr_event_speakers_past|bleach_tags|safe }}
102102
{% endif %}
103103
{% if sr_event_media_coverage %}
104104

105105
+ Media Coverage
106-
{{ sr_event_media_coverage|strip_tags|safe }}
106+
{{ sr_event_media_coverage|bleach_tags|safe }}
107107
{% endif %}
108108
{% if sr_event_sponsors %}
109109

110110
+ Event Sponsors
111-
{{ sr_event_sponsors|strip_tags|safe }}
111+
{{ sr_event_sponsors|bleach_tags|safe }}
112112
{% endif %}
113113
{% if sr_event_confirmation_deadline %}
114114

@@ -126,12 +126,12 @@ Presentation Details
126126
{% if sr_presentation_panelists %}
127127

128128
+ Other Panelists
129-
{{ sr_presentation_panelists|strip_tags|safe }}
129+
{{ sr_presentation_panelists|bleach_tags|safe }}
130130
{% endif %}
131131
{% if sr_presentation_topic %}
132132

133133
+ Topic of Presentation
134-
{{ sr_presentation_topic|strip_tags|safe }}
134+
{{ sr_presentation_topic|bleach_tags|safe }}
135135
{% endif %}
136136
{% if sr_presentation_length %}
137137

bedrock/press/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: utf8 -*-
1+
# -*- coding: utf-8 -*-
22
# This Source Code Form is subject to the terms of the Mozilla Public
33
# License, v. 2.0. If a copy of the MPL was not distributed with this
44
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -245,7 +245,7 @@ def test_emails_not_escaped(self):
245245
"""
246246

247247
STRING1 = u"<blink>J'adore Citröns</blink> & <Piñatas> so there"
248-
EXPECTED1 = u"J'adore Citröns & <Piñatas> so there"
248+
EXPECTED1 = u"J'adore Citröns & so there"
249249

250250
STRING2 = u"J'adore Piñatas & <fromage> so here"
251251
EXPECTED2 = u"J'adore Piñatas & so here"

vendor-local/src/bleach

Submodule bleach added at f9fc1c5

vendor-local/src/html5lib

Submodule html5lib added at 3b3c103

0 commit comments

Comments
 (0)