strip_all_tags_but_br_filter would return HTML safe string.

Now returning HTML safe string to template instead
of just bleaching string for br tags.

LEARNER-3930
This commit is contained in:
Adeel Khan
2018-01-22 18:31:24 +05:00
parent e75a2ef5d4
commit b497210f17
4 changed files with 29 additions and 2 deletions

View File

@@ -37,7 +37,7 @@ def HTML(html): # pylint: disable=invalid-name
def strip_all_tags_but_br(string_to_strip):
"""
Strips all tags from a string except <br/>
Strips all tags from a string except <br/> and marks as HTML.
Usage:
<%page expression_filter="h"/>
@@ -53,4 +53,4 @@ def strip_all_tags_but_br(string_to_strip):
string_to_strip = decode.utf8(string_to_strip)
string_to_strip = bleach.clean(string_to_strip, tags=['br'], strip=True)
return string_to_strip
return HTML(string_to_strip)

View File

@@ -90,3 +90,12 @@ class FormatHtmlTest(unittest.TestCase):
self.assertIn('<br>', rendered_template)
self.assertNotIn('<script>', rendered_template)
def test_strip_all_tags_but_br_returns_html(self):
"""
Verify filter returns HTML Markup safe string object
"""
html = strip_all_tags_but_br('{name}<br><script>')
html = html.format(name='Rock & Roll')
self.assertEqual(html.decode(), u'Rock &amp; Roll<br>')