ultisuite-backend/internal/mail/sanitize/preheader_test.go
R3D347HR4Y cd0a80f5e8 huhu
2026-05-25 13:52:27 +02:00

42 lines
1.2 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package sanitize
import (
"strings"
"testing"
)
func TestStripHiddenEmailHTML_removesMailchimpPreheaderPadding(t *testing.T) {
const padding = "͏ \u200c \u00a0 \u2007 "
in := `<div style="display: none; max-height: 0px; overflow: hidden;">` + strings.Repeat(padding, 20) + `</div>` +
`<p>All motor files are now structured by model.</p>`
out := StripHiddenEmailHTML(in)
if strings.Contains(out, "\u034f") || strings.Contains(out, "\u200c") {
t.Fatalf("invisible padding remains: %q", out)
}
if !strings.Contains(out, "All motor files") {
t.Fatalf("visible content removed: %q", out)
}
}
func TestSanitizeHTML_stripsHiddenPreheader(t *testing.T) {
in := `<div style="display: none;">hidden junk</div><p>Hello world</p>`
got := SanitizeHTML(in)
if strings.Contains(got, "hidden junk") {
t.Fatalf("hidden preheader leaked after sanitize: %q", got)
}
if !strings.Contains(got, "Hello world") {
t.Fatalf("visible content missing: %q", got)
}
}
func TestStripInvisibleTextRuns(t *testing.T) {
in := "Hello " + strings.Repeat("\u034f\u200c\u00a0\u2007 ", 30) + "world"
got := StripInvisibleTextRuns(in)
if strings.Contains(got, "\u034f") {
t.Fatalf("padding remains: %q", got)
}
if got != "Hello world" {
t.Fatalf("got %q", got)
}
}