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:
@@ -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)
|
||||
|
||||
@@ -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 & Roll<br>')
|
||||
|
||||
Reference in New Issue
Block a user