Skip to content

Render plain text properly in the default HTML email template - #1119

Open
jarovarga wants to merge 1 commit into
cakephp:5.xfrom
jarovarga:ticket-1115-html-email-template
Open

jarovarga wants to merge 1 commit into
cakephp:5.xfrom
jarovarga:ticket-1115-html-email-template

Conversation

@jarovarga

Copy link
Copy Markdown

Fixes #1115.

As agreed in the issue, $content is treated as plain text, the same string that text/default.php echoes.

  • Escape each line with h().
  • Separate paragraphs by blank lines (including whitespace-only lines) and turn single line breaks into <br>, so hard-wrapped text stays in one paragraph like in the text part.
  • Handle \r\n and \r, and render no empty paragraphs.
  • Use (*BSR_ANYCRLF) in the patterns proposed in the issue: without the u modifier, \R also matches the byte 0x85, which occurs inside UTF-8 characters such as "Å". Adding u instead would make preg_split() fail on invalid UTF-8 and drop the content.
  • Add DefaultTemplateTest covering paragraphs, escaping, multibyte characters and empty content.

The template wrapped every line in its own paragraph without escaping
it, so user-supplied text was inserted as markup, blank lines became
empty paragraphs and CRLF input left carriage returns behind.

Treat $content as plain text: escape each line, separate paragraphs
by blank lines and turn single line breaks into <br>. Restrict \R to
CR and LF so that the UTF-8 byte 0x85 in characters such as "Å" is
not taken as a line break.

Fixes cakephp#1115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default HTML email template: unescaped lines, empty paragraphs and stray carriage returns

1 participant