package mailhtml import "testing" // The inliner and the text renderer run on every send that carries a // stylesheet, on markup the sender pasted from somewhere else. A panic here // would take down a worker mid-send, so neither may ever do worse than return // the body it was given. func FuzzInlineCSS(f *testing.F) { f.Add(`

hi

`) f.Add(`x`) f.Add(``) f.Add(`

x

`) f.Add(`

x

`) f.Add(``) f.Add("") // The two inputs that found real bugs. Seeds run on every `go test`, so // they guard the fixes even where the fuzzer itself is not run: a sheet // the parser cannot read must not be deleted, and a body whose case fold // changes its length must not move the insertion point. f.Add("

hi

") f.Add("\xa4\xa4\xa4\xa4") f.Add("

\u0130stanbul

") // Table layout, which is what the append pass has to reason about. f.Add(`
ab
`) f.Add(`
x`) f.Add(`

x

`) f.Fuzz(func(t *testing.T, body string) { out := InlineCSS(body) if body != "" && out == "" && HasStyleBlock(body) { // An empty result is only legitimate when the input was empty. t.Errorf("InlineCSS emptied a non-empty body: %q", body) } _ = ToPlainText(body) _ = Lint(body, len(body)) _ = InsertBeforeBodyEnd(body, "[F]") // The append pass may only ever hand back the caller's own bytes with // something inserted at one offset: it runs on markup a sender pasted // from somewhere else, and a body it rewrote is a message the author // did not write. if out := AppendToContent(body, "[F]"); !isSplice(body, out) { t.Errorf("AppendToContent rewrote the body:\n in %q\nout %q", body, out) } }) }