Fix #923: Use same markdown widget for all content fields (rules, description, reports, notes, etc.)

This commit is contained in:
Eliot Berriot 2020-02-06 15:52:08 +01:00
parent 8d29adf6be
commit 7850ca3e1c
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
12 changed files with 128 additions and 75 deletions

View file

@ -103,27 +103,40 @@ def test_join_url(start, end, expected):
@pytest.mark.parametrize(
"text, content_type, expected",
"text, content_type, permissive, expected",
[
("hello world", "text/markdown", "<p>hello world</p>"),
("hello world", "text/plain", "<p>hello world</p>"),
("<strong>hello world</strong>", "text/html", "<strong>hello world</strong>"),
("hello world", "text/markdown", False, "<p>hello world</p>"),
("hello world", "text/plain", False, "<p>hello world</p>"),
(
"<strong>hello world</strong>",
"text/html",
False,
"<strong>hello world</strong>",
),
# images and other non whitelisted html should be removed
("hello world\n![img](src)", "text/markdown", "<p>hello world</p>"),
("hello world\n![img](src)", "text/markdown", False, "<p>hello world</p>"),
(
"hello world\n\n<script></script>\n\n<style></style>",
"text/markdown",
False,
"<p>hello world</p>",
),
(
"<p>hello world</p><script></script>\n\n<style></style>",
"text/html",
False,
"<p>hello world</p>",
),
(
'<p class="foo">hello world</p><script></script>\n\n<style></style>',
"text/markdown",
True,
'<p class="foo">hello world</p>',
),
],
)
def test_render_html(text, content_type, expected):
result = utils.render_html(text, content_type)
def test_render_html(text, content_type, permissive, expected):
result = utils.render_html(text, content_type, permissive=permissive)
assert result == expected