Sanitizer: a newsletter's <title> showed as a line above the body
<title> is not an allowed tag, so nh3 unwrapped it and kept its text — "mailer", "Email template" or the subject rendered before the content. It is now dropped with its content, both in the sanitized HTML and in the text derived from HTML-only mail (snippet and search). SANITIZER_VERSION goes to 4 so stored bodies re-sanitize from the raw blob on next render. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -83,7 +83,14 @@ def _addresses(msg: EmailMessage, header: str) -> list[dict[str, str]]:
|
||||
|
||||
def _html_to_text(html: str) -> str:
|
||||
"""Derive plain text from HTML by stripping all tags (SPEC §6.4 nh3 strip)."""
|
||||
return nh3.clean(html, tags=set(), attributes={}, strip_comments=True)
|
||||
return nh3.clean(
|
||||
html,
|
||||
tags=set(),
|
||||
attributes={},
|
||||
strip_comments=True,
|
||||
# The document <title> is not body text; unwrapped it would lead the snippet.
|
||||
clean_content_tags={"script", "style", "title"},
|
||||
)
|
||||
|
||||
|
||||
def _get_body_content(msg: EmailMessage, subtype: str) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user