package seaglass_test import ( "testing" "git.golem15.com/golem15/summercms/modules/seaglass" ) // TestSanitizeByteStable pins D-10's byte-stability promise: HTML the policy // keeps whole comes back byte for byte, with attributes in their source order, // entities as written, whitespace and quoting untouched, and a zero report. func TestSanitizeByteStable(t *testing.T) { for _, html := range []string{ "", "plain text", "

One paragraph.

", "

Mushrooms can help.

\n\n

Second.

", `attributes in source order`, `relative mail tel`, `

Entities: & <tag> "q" 's'   © — —

`, `

Raw text quotes: It's "fine" & done

`, `

single quotes stay

`, `

upper-case attribute name

`, "", "
  1. a
    1. nested
", `

heading

h3

quote

`, `

line
break
self-closed

`, `An image`, `
h
c
`, `

styled

`, `
Tea
`, `

1

note

`, `
if a < b { return }
`, "

Zażółć gęślą jaźń — unicode “quotes”

", } { got, report := seaglass.SanitizeReport(html) if got != html { t.Errorf("SanitizeReport(%q) = %q, want the input byte for byte", html, got) } if report.Changed || report.ElementCount != 0 || report.AttributeCount != 0 || report.Comments != 0 || len(report.Elements) != 0 || len(report.Attributes) != 0 { t.Errorf("SanitizeReport(%q) report = %+v, want zero", html, report) } if out := seaglass.Sanitize(html); out != html { t.Errorf("Sanitize(%q) = %q", html, out) } if err := seaglass.Check(html); err != nil { t.Errorf("Check(%q) = %v", html, err) } } }