Skip to content

Commit

Permalink
Fixed markdown bug rendering null values, closes #124
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 3, 2021
1 parent 91a714e commit 119a102
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions django_sql_dashboard/templatetags/django_sql_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def sql_dashboard_bleach(value):

@register.filter
def sql_dashboard_markdown(value):
value = value or ""
return mark_safe(
bleach.linkify(
bleach.clean(
Expand Down
17 changes: 14 additions & 3 deletions test_project/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,25 @@ def test_big_number_widget(admin_client, dashboard_db):
) in html


def test_markdown_widget(admin_client, dashboard_db):
@pytest.mark.parametrize(
"sql,expected",
(
(
"select '# Foo\n\n## Bar [link](/)' as markdown",
'<h1>Foo</h1>\n<h2>Bar <a href="/" rel="nofollow">link</a></h2>',
),
("select null as markdown", ""),
),
)
def test_markdown_widget(admin_client, dashboard_db, sql, expected):
response = admin_client.post(
"/dashboard/",
{"sql": "select '# Foo\n\n## Bar [link](/)' as markdown"},
{"sql": sql},
follow=True,
)
assert response.status_code == 200
html = response.content.decode("utf-8")
assert '<h1>Foo</h1>\n<h2>Bar <a href="/" rel="nofollow">link</a></h2>' in html
assert expected in html


def test_html_widget(admin_client, dashboard_db):
Expand Down

0 comments on commit 119a102

Please sign in to comment.