Skip to content

Commit

Permalink
🐛 [#4978] Fix accidental HTML escaping in summary PDF/confirmation email
Browse files Browse the repository at this point in the history
While the component/formatter properly takes care of conditional
escaping by leveraging format_html and friends, the post-processor
was converting the SafeString into a regular string again by doing
string-interpolation for the file names, which leads to the full
result being HTML escaped again.

In HTML mode, the prefix 'attachment' is now dropped, as the markup and
context of the label/field should provide sufficient information and
the 'attachment:' prefix looks odd in combination with the <ul> markup.
  • Loading branch information
sergei-maertens committed Jan 6, 2025
1 parent 7f8fd3b commit f36da6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/openforms/emails/tests/test_confirmation_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ def test_attachment(self):
self.assertTagWithTextIn("td", "Last name", rendered_content)
self.assertTagWithTextIn("td", "Doe", rendered_content)
self.assertTagWithTextIn("td", "File", rendered_content)
self.assertTagWithTextIn(
"td", _("attachment: %s") % "my-image.jpg", rendered_content
)
self.assertTagWithTextIn("td", "my-image.jpg", rendered_content)

@patch(
"openforms.emails.templatetags.appointments.get_plugin",
Expand Down
10 changes: 7 additions & 3 deletions src/openforms/formio/formatters/formio.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ def normalise_value_to_list(self, component: Component, value: Any):
return value

def process_result(self, component: Component, formatted: str) -> str:
# prefix joined filenames to match legacy
if formatted:
if not formatted:
return ""

# Make sure we don't mangle safe-strings!
if self.as_html:
return formatted
else:
return _("attachment: %s") % formatted
return formatted

def format(self, component: Component, value: dict) -> str:
# this is only valid for display to the user (because filename component option, dedupe etc)
Expand Down

0 comments on commit f36da6f

Please sign in to comment.