Repository navigation
fix(messaging): decode HTML entities in the plain-text part of emails - #14118
Conversation
The text part is the HTML body with tags stripped, so entities stayed literal: apostrophes showed as ' and the preview padding as ‌ ... runs.
🔵 Tier A · Mergeable after minor fixes
The messaging package now builds HTML emails’ plain-text alternatives from parsed visible content, decoding entities, omitting non-visible blocks, and retaining useful link destinations. It also declares the DOM extension and adds MIME tests for the decoded alternative and preserved HTML body. The latest change treats carriage returns as collapsible whitespace during rendering and preview-padding detection. Latest changes: The newest commit adds carriage returns to the whitespace handling for ordinary text nodes and preview-padding nodes.
Fix with agent prompt### Issue 1
packages/messaging/src/Adapter/Email/Mime.php:117-119
**Add a regression test for entity decoding**
The existing `MimeTest::testMarkupBringsAPlainAlternativeWithIt` contains no entities, so it passes even if this fix is removed. Please add coverage for decoded named/numeric entities (including quotes and escaped angle brackets) in the plain alternative, and verify that HTML and plain-text input remain unchanged.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 3
⏳ Still open from earlier reviews · 1
✅ Fixed since the last review · 1
Reviewed the commits since |
| return trim(html_entity_decode(strip_tags( | ||
| preg_replace('/<style\b[^>]*>(.*?)<\/style>/is', '', $email->getContent()) ?? '', | ||
| )); | ||
| ), ENT_QUOTES | ENT_HTML5, 'UTF-8')); |
There was a problem hiding this comment.
Add a regression test for entity decoding
The existing MimeTest::testMarkupBringsAPlainAlternativeWithIt contains no entities, so it passes even if this fix is removed. Please add coverage for decoded named/numeric entities (including quotes and escaped angle brackets) in the plain alternative, and verify that HTML and plain-text input remain unchanged.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/messaging/src/Adapter/Email/Mime.php
Line: 117-119
Comment:
**Add a regression test for entity decoding**
The existing `MimeTest::testMarkupBringsAPlainAlternativeWithIt` contains no entities, so it passes even if this fix is removed. Please add coverage for decoded named/numeric entities (including quotes and escaped angle brackets) in the plain alternative, and verify that HTML and plain-text input remain unchanged.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Named and numeric entities, quotes and escaped angle brackets read as text in the plain alternative, while the HTML part keeps them encoded.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Walk the parsed document instead of stripping tags: skip head, style, script and hidden preheaders, collapse source whitespace, break lines at blocks and <br>, and keep each link's address beside its label so a button still leads somewhere.
The preheader is the email's summary and readers of the text part expect it, so only its invisible padding is dropped.
…to fix/email-text-part-entities
… the plain-text part Drop invisible characters only from a text node made of nothing else, so joiners and direction marks in real text survive; keep whitespace inside pre as written; declare ext-dom.
The padding check above already returns for a text node with no words.
The parser always creates a body, and a childless non-element node already renders to nothing through the general path.
Rendering starts at the body, so head is never visited; the parser lowercases HTML element names, never makes an empty text node and normalizes carriage returns to newlines.
The parser normalizes source line endings, but still puts a carriage return in a text node, which the plain-text part would turn into a line break.
…ntities fix(messaging): decode HTML entities in the plain-text part of emails (cherry picked from commit 83cbe41)
Mime::text()builds the plain-text part by stripping tags from the HTML body, but never decodes entities. Every HTML email therefore has literal entities in its text part. In auth emails that means "If you didn't ask to reset your password…", followed by the preview padding as a long run of ‌…text.This decodes entities after stripping tags (
ENT_QUOTES | ENT_HTML5, UTF-8).Verification: I rendered the recovery email through the real
Mailsworker into a local SMTP sink and scored it withrspamc(rspamd 4.2.1).R_PARTS_DIFFER(0.85) no longer fires.HIDDEN_TEXTis unchanged here; fix(mails): use spam-safe characters for email preview padding #14111 addresses that.MimeTestpasses, and pint and phpstan pass on the file.Related: #14089, #14111