Strip style/script/xml blocks and table structure before sanitizing pasted HTML

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Claude Fable 5
2026-08-22 13:16:11 +02:00
parent d187f558b2
commit a4ca026e82
+9 -2
View File
@@ -34,10 +34,17 @@ final class SurveyHtmlSanitizer
$html = $this->convertPlainTextToHtml($html);
}
// Elemente samt Inhalt komplett entfernen, bevor der Parser sie sieht
// Word/Outlook liefern <style>- und <xml>-Blöcke mit, deren Text sonst
// (je nach Parser-Kontext) als sichtbarer Inhalt übrig bleiben kann.
$html = (string) preg_replace('#<(script|style|head|title|iframe|object|template|noscript|xml|svg|math)\b[^>]*>.*?</\1\s*>#is', ' ', $html);
$html = (string) preg_replace('#<!--.*?-->#s', ' ', $html);
// Fremde Blockelemente (z. B. aus dem Backend-TinyMCE oder aus Word-Kopien)
// in Absätze überführen, damit der Text nicht zusammenläuft.
$html = (string) preg_replace('#<(div|h[1-6]|blockquote|section|article|header|footer|pre|address)\b[^>]*>#i', '<p>', $html);
$html = (string) preg_replace('#</(div|h[1-6]|blockquote|section|article|header|footer|pre|address)>#i', '</p>', $html);
$html = (string) preg_replace('#<(div|h[1-6]|blockquote|section|article|header|footer|pre|address|tr|dt|dd)\b[^>]*>#i', '<p>', $html);
$html = (string) preg_replace('#</(div|h[1-6]|blockquote|section|article|header|footer|pre|address|tr|dt|dd)>#i', '</p>', $html);
$html = (string) preg_replace('#</t[dh]>\s*<t[dh]\b[^>]*>#i', ' ', $html);
$clean = $this->getSanitizer()->sanitize($html);