diff --git a/notifications_utils/template.py b/notifications_utils/template.py index 946d978c..38e7b53b 100644 --- a/notifications_utils/template.py +++ b/notifications_utils/template.py @@ -378,7 +378,7 @@ def preheader(self): Field( self.content, self.values, - html="escape", + html="strip" if self.allow_html else "escape", markdown_lists=True, ) ) diff --git a/notifications_utils/version.py b/notifications_utils/version.py index 39d67450..763bc1df 100644 --- a/notifications_utils/version.py +++ b/notifications_utils/version.py @@ -1,2 +1,2 @@ -__version__ = "46.1.0" +__version__ = "46.2.0" # GDS version '34.0.1' diff --git a/tests/test_template_types.py b/tests/test_template_types.py index 708b7e53..ffbefaae 100644 --- a/tests/test_template_types.py +++ b/tests/test_template_types.py @@ -338,6 +338,28 @@ def test_content_of_preheader_in_html_emails( assert mock_jinja_template.call_args[0][0]["preheader"] == expected_preheader +@pytest.mark.parametrize( + "allow_html, content, expected_preheader", + [ + (True, "Hello World", "Hello World"), + (False, "Hello World", "Hello World"), + (True, "
Hello World
", "Hello World"), + (False, "
Hello World
", "<div>Hello World</div>"), + (True, '
Hello World
', "Hello World"), + (False, '
Hello World
', "<div><img src=”file.png” />Hello World</div>"), + ], +) +@mock.patch("notifications_utils.template.HTMLEmailTemplate.jinja_template.render", return_value="mocked") +def test_content_of_preheader_in_html_emails_with_allow_html( + mock_jinja_template, + allow_html: bool, + content: str, + expected_preheader: str, +): + assert str(HTMLEmailTemplate({"content": content, "subject": "subject"}, allow_html=allow_html)) == "mocked" + assert mock_jinja_template.call_args[0][0]["preheader"] == expected_preheader + + @pytest.mark.parametrize( "template_class, extra_args, result, markdown_renderer", [