diff --git a/django_sql_dashboard/templatetags/django_sql_dashboard.py b/django_sql_dashboard/templatetags/django_sql_dashboard.py index fc3eb72..c9f758e 100644 --- a/django_sql_dashboard/templatetags/django_sql_dashboard.py +++ b/django_sql_dashboard/templatetags/django_sql_dashboard.py @@ -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( diff --git a/test_project/test_widgets.py b/test_project/test_widgets.py index 5642c7a..396ac51 100644 --- a/test_project/test_widgets.py +++ b/test_project/test_widgets.py @@ -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", + '

Foo

\n

Bar link

', + ), + ("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 '

Foo

\n

Bar link

' in html + assert expected in html def test_html_widget(admin_client, dashboard_db):