Fix HTML showing up on the breaking change page

41fa158635 added a proper Jinja filter
for formatting lists, which was better than the previous macro-based
solution.

It didn’t, however, account for HTML properly. It  did the default Jinja
thing of escaping everything. Since we render lists of placeholders
by putting HTML before and after each item, this didn’t work (the HTML
got escaped and appeared on the page).

So this commit does the escaping of HTML outside Jinja, in the
user-submitted bits of the input only, then passes the whole thing
through as a `Markup` instance which doesn’t get escaped by Jinja.
This commit is contained in:
Chris Hill-Scott
2017-03-06 12:54:27 +00:00
parent cd21b39d3f
commit 536d091d85
2 changed files with 12 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import pytest
from flask import Markup
from app import formatted_list
@@ -11,6 +12,12 @@ from app import formatted_list
([1], {'prefix': 'foo', 'prefix_plural': 'bar'}, 'foo 1'),
([1, 2, 3], {'before_each': 'a', 'after_each': 'b'}, 'a1b, a2b and a3b'),
([1, 2, 3], {'conjunction': 'foo'}, '1, 2 foo 3'),
(['&'], {'before_each': '<i>', 'after_each': '</i>'}, '<i>&amp;</i>'),
([1, 2, 3], {'before_each': '<i>', 'after_each': '</i>'}, '<i>1</i>, <i>2</i> and <i>3</i>'),
])
def test_formatted_list(items, kwargs, expected_output):
assert formatted_list(items, **kwargs) == expected_output
def test_formatted_list_returns_markup():
assert isinstance(formatted_list([0]), Markup)