42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
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)
|
||
}
|
||
}
|