60 lines
2.5 KiB
Go
60 lines
2.5 KiB
Go
package sanitize
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestStripHiddenEmailHTML_preservesFontSize0WithChildElements(t *testing.T) {
|
|
in := `<div style="font-size:0;text-align:center">` +
|
|
`<div style="display:inline-block;font-size:14px;width:200px">Column 1</div>` +
|
|
`<div style="display:inline-block;font-size:14px;width:200px">Column 2</div></div>`
|
|
out := StripHiddenEmailHTML(in)
|
|
if !strings.Contains(out, "Column 1") || !strings.Contains(out, "Column 2") {
|
|
t.Fatalf("inline-block columns removed by font-size:0 stripping: %q", out)
|
|
}
|
|
}
|
|
|
|
func TestStripHiddenEmailHTML_preservesMultiColumnTable(t *testing.T) {
|
|
in := `<table width="600"><tr><td style="font-size:0">` +
|
|
`<table width="300" style="display:inline-block"><tr><td style="font-size:14px;padding:10px">Left</td></tr></table>` +
|
|
`<table width="300" style="display:inline-block"><tr><td style="font-size:14px;padding:10px">Right</td></tr></table>` +
|
|
`</td></tr></table>`
|
|
out := StripHiddenEmailHTML(in)
|
|
if !strings.Contains(out, "Left") || !strings.Contains(out, "Right") {
|
|
t.Fatalf("multi-column table content removed: %q", out)
|
|
}
|
|
}
|
|
|
|
func TestStripHiddenEmailHTML_stillStripsFontSize0Preheader(t *testing.T) {
|
|
in := `<span style="font-size:0">Hidden preview text</span><p>Visible content</p>`
|
|
out := StripHiddenEmailHTML(in)
|
|
if strings.Contains(out, "Hidden preview text") {
|
|
t.Fatalf("font-size:0 preheader text should be stripped: %q", out)
|
|
}
|
|
if !strings.Contains(out, "Visible content") {
|
|
t.Fatalf("visible content missing: %q", out)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeHTML_preservesFontSize0InlineBlockLayout(t *testing.T) {
|
|
in := `<div style="font-size:0;text-align:center">` +
|
|
`<div style="display:inline-block;font-size:14px;width:200px">Column 1</div>` +
|
|
`<div style="display:inline-block;font-size:14px;width:200px">Column 2</div></div>`
|
|
out := SanitizeHTML(in)
|
|
if !strings.Contains(out, "Column 1") || !strings.Contains(out, "Column 2") {
|
|
t.Fatalf("full sanitize pipeline removed inline-block content: %q", out)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeHTML_preservesTableFontSize0Wrapper(t *testing.T) {
|
|
in := `<table width="600"><tr><td style="font-size:0">` +
|
|
`<table width="300" style="display:inline-block"><tr><td style="font-size:14px">Left content</td></tr></table>` +
|
|
`<table width="300" style="display:inline-block"><tr><td style="font-size:14px">Right content</td></tr></table>` +
|
|
`</td></tr></table>`
|
|
out := SanitizeHTML(in)
|
|
if !strings.Contains(out, "Left content") || !strings.Contains(out, "Right content") {
|
|
t.Fatalf("table multi-column content lost after sanitize: %q", out)
|
|
}
|
|
}
|