Skip to content

Commit af3cba5

Browse files
authored
Merge pull request #1300 from OpenTechFund/bugfix/gh-1299-submission-revision-diff-chrome
Sanitising submission revision output before diff
2 parents a8c15fd + 6718411 commit af3cba5

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

opentech/apply/funds/differ.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
from bleach.sanitizer import Cleaner
12
from bs4 import BeautifulSoup
23
from difflib import SequenceMatcher
34

4-
import bleach
5-
65
from django.utils.html import format_html
76
from django.utils.text import mark_safe
87

@@ -28,17 +27,18 @@ def compare(answer_a, answer_b, should_bleach=True):
2827
return answer_b
2928

3029
if should_bleach:
30+
cleaner = Cleaner(tags=['h4'], attributes={}, strip=True)
3131
if isinstance(answer_a, str):
32-
answer_a = bleach.clean(answer_a)
32+
answer_a = cleaner.clean(answer_a)
3333
else:
3434
answer_a = str(answer_a)
3535

3636
if isinstance(answer_b, str):
37-
answer_b = bleach.clean(answer_b)
37+
answer_b = cleaner.clean(answer_b)
3838
else:
3939
answer_b = str(answer_b)
4040

41-
diff = SequenceMatcher(lambda x: '\n' in x, answer_a, answer_b)
41+
diff = SequenceMatcher(None, answer_a, answer_b)
4242
output = []
4343
added = []
4444
deleted = []

opentech/apply/funds/templates/funds/applicationrevision_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h5>For <a href="{% url "funds:submissions:detail" submission.id %}">{{ submissi
1414
{% for revision in object_list %}
1515
<li class="revision__item">
1616
<p class="revision__meta">
17-
<span class="revision__date">{{ revision.timestamp|date:"m.d.y h:iA e"}} </span>
17+
<span class="revision__date">{{ revision.timestamp|date:"Y-m-d H:i e"}} </span>
1818
by {{ revision.author }}
1919
{% if forloop.first %}
2020
<span class="revision__current">- current</span>

opentech/apply/funds/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,15 +801,15 @@ def compare_revisions(self, from_data, to_data):
801801

802802
# Compare all the required fields
803803
diffed_required = [
804-
compare(*fields, should_bleach=False)
804+
compare(*fields)
805805
for fields in zip(from_required, to_required)
806806
]
807807
for field, diff in zip(self.object.named_blocks, diffed_required):
808808
setattr(self.object, 'get_{}_display'.format(field), diff)
809809

810810
# Compare all the answers
811811
diffed_text_fields_answers = [
812-
compare(*fields, should_bleach=False)
812+
compare(*fields)
813813
for fields in zip(from_rendered_text_fields, to_rendered_text_fields)
814814
]
815815

0 commit comments

Comments
 (0)