Added 'format_html' utility for formatting HTML fragments safely

This commit is contained in:
Luke Plant 2012-06-30 18:54:38 +01:00
parent f33e150369
commit bee498f3a2
3 changed files with 81 additions and 0 deletions

View file

@ -34,6 +34,17 @@ class TestUtilsHtml(unittest.TestCase):
# Verify it doesn't double replace &.
self.check_output(f, '<&', '&lt;&amp;')
def test_format_html(self):
self.assertEqual(
html.format_html(u"{0} {1} {third} {fourth}",
u"< Dangerous >",
html.mark_safe(u"<b>safe</b>"),
third="< dangerous again",
fourth=html.mark_safe(u"<i>safe again</i>")
),
u"&lt; Dangerous &gt; <b>safe</b> &lt; dangerous again <i>safe again</i>"
)
def test_linebreaks(self):
f = html.linebreaks
items = (