Skip to content

Commit 9b67868

Browse files
committed
Sanitize all tags
1 parent d1cc155 commit 9b67868

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/common/text_sanitizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def sanitize_text(text):
1010
if text is None:
1111
return
1212

13-
return bleach.clean(text=text)
13+
return bleach.clean(text=text, tags=[])
1414

1515
@staticmethod
1616
def allow_img_src(tag, name, value):

tests/common/test_text_sanitizer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ def test_sanitize_text(self):
1212
target_html = '''
1313
Sample text
1414
<script>document.alert('evil')</script>
15+
<b>bold</b>
16+
<h2>sample h2</h2>
17+
<h3>sample h3</h3>
18+
<i>icon</i><p>sentence</p><u>under bar</u>
19+
<b>bold</b><br><blockquote>blockquote</blockquote>
1520
'''
1621

1722
expected_html = '''
1823
Sample text
1924
&lt;script&gt;document.alert('evil')&lt;/script&gt;
25+
&lt;b&gt;bold&lt;/b&gt;
26+
&lt;h2&gt;sample h2&lt;/h2&gt;
27+
&lt;h3&gt;sample h3&lt;/h3&gt;
28+
&lt;i&gt;icon&lt;/i&gt;&lt;p&gt;sentence&lt;/p&gt;&lt;u&gt;under bar&lt;/u&gt;
29+
&lt;b&gt;bold&lt;/b&gt;&lt;br&gt;&lt;blockquote&gt;blockquote&lt;/blockquote&gt;
2030
'''
2131

2232
result = TextSanitizer.sanitize_text(target_html)

0 commit comments

Comments
 (0)