Preserve literal text when wrapping sanitized mail markup
All checks were successful
Tests und Docker-Image / Tests und Frontend-Build (push) Successful in 51s
Tests und Docker-Image / Leeres Produktionsimage bauen und veröffentlichen (push) Successful in 1m52s

This commit is contained in:
Weapie 2026-11-05 17:56:06 +01:00
parent c72c72e41e
commit 662fec078c
2 changed files with 8 additions and 1 deletions

View File

@ -157,7 +157,9 @@ export function mailHtml(html, { resolveImage = safeImageUrl } = {}) {
) )
.join('') .join('')
const shell = sanitizeHtml(`<div${serialized}></div>`, options) const shell = sanitizeHtml(`<div${serialized}></div>`, options)
return shell.replace(/^<div/, `<div data-mail-${kind}`).replace('</div>', content + '</div>') return shell
.replace(/^<div/, `<div data-mail-${kind}`)
.replace('</div>', () => content + '</div>')
} }
const styled = sheets const styled = sheets
.filter(Boolean) .filter(Boolean)

View File

@ -13,6 +13,11 @@ const fixture = (name) => readFileSync(new URL('./fixtures/' + name, import.meta
const png = const png =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+a3ioAAAAASUVORK5CYII=' 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+a3ioAAAAASUVORK5CYII='
test('Mail text containing literal dollar replacement sequences is preserved', () => {
const clean = mailHtml('<p>Code: $&amp; $$ $`</p>')
assert(clean.includes('<p>Code: $&amp; $$ $`</p>'))
})
test('Newsletter rendering preserves stylesheets, responsive rules, hidden preheaders, table geometry and source order', () => { test('Newsletter rendering preserves stylesheets, responsive rules, hidden preheaders, table geometry and source order', () => {
const clean = mailHtml(fixture('mail-newsletter.html')) const clean = mailHtml(fixture('mail-newsletter.html'))
assert.match(clean, /<style>/) assert.match(clean, /<style>/)