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

41 lines
1.3 KiB
Go

package sanitize
import (
"strings"
"testing"
)
func TestSanitizeHTML_preservesImgLazyAndSrcset(t *testing.T) {
in := `<img data-src="https://cdn.example.com/hero.png" alt="hero">` +
`<img srcset="https://cdn.example.com/a.png 1x" src="https://cdn.example.com/f.png">`
got := SanitizeHTML(in)
if !strings.Contains(got, `data-src="https://cdn.example.com/hero.png"`) {
t.Fatalf("expected data-src preserved, got %q", got)
}
if !strings.Contains(got, `src="https://cdn.example.com/hero.png"`) {
t.Fatalf("expected lazy src promoted to src, got %q", got)
}
if !strings.Contains(got, `srcset="https://cdn.example.com/a.png 1x"`) {
t.Fatalf("expected srcset preserved, got %q", got)
}
if !strings.Contains(got, `src="https://cdn.example.com/f.png"`) {
t.Fatalf("expected src preserved, got %q", got)
}
}
func TestSanitizeHTML_preservesCidImageSrc(t *testing.T) {
in := `<img src="cid:logo@mail" alt="logo">`
got := SanitizeHTML(in)
if !strings.Contains(got, `src="cid:logo@mail"`) {
t.Fatalf("expected cid src preserved, got %q", got)
}
}
func TestSanitizeHTML_preservesRelativeImgSrc(t *testing.T) {
in := `<img src="/campaign/logo.png" alt="logo">`
got := SanitizeHTML(in)
if !strings.Contains(got, `src="/campaign/logo.png"`) {
t.Fatalf("expected relative src preserved, got %q", got)
}
}