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
commit 7850ca3e1c
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
12 changed files with 130 additions and 77 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

View file

@ -281,3 +281,15 @@ def test_can_render_text_preview(api_client, db):
expected = {"rendered": utils.render_html(payload["text"], "text/markdown")}
assert response.status_code == 200
assert response.data == expected
def test_can_render_text_preview_permissive(api_client, db):
payload = {"text": "Hello world", "permissive": True}
url = reverse("api:v1:text-preview")
response = api_client.post(url, payload)
expected = {
"rendered": utils.render_html(payload["text"], "text/markdown", permissive=True)
}
assert response.status_code == 200
assert response.data == expected