package safehtml import ( "strings" "testing" ) func TestDescription(t *testing.T) { const rel = ` rel="nofollow ugc noopener noreferrer" target="_blank"` for _, c := range []struct{ in, want string }{ // Kept. {`Hi
Made by me
`, `Hi
Made by me
`}, {`x`, `x`}, {`

x

`, `

x

`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`A`, `A`}, {`
x
`, `
x
`}, {`

b

c
d
`, `

b

c
d
`}, {`5 < 6 & "quotes"`, `5 < 6 & "quotes"`}, // Removed. {`x`, `x`}, {`x`, `x`}, {`ipt>alert(1)`, `ipt>alert(1)`}, {``, ``}, {``, ``}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {``, ``}, {``, ``}, {``, ``}, {`no src`, ``}, {`

x

`, `

x

`}, {`

x

`, `

x

`}, {`

x

`, `

x

`}, {`

x

`, `

x

`}, {`

x

`, `

x

`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`
x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, {`

unclosed`, `

unclosed`}, {`misnested`, `misnested`}, {`alert(1)>x`, `alert(1)>x`}, {``, ``}, {`x`, `x`}, } { if got := Description(c.in); got != c.want { t.Errorf("Description(%q)\n got %q\nwant %q", c.in, got, c.want) } } } func TestNoScriptAnywhere(t *testing.T) { for _, in := range []string{ `</script>`, `x`, ``, ``, `x`, ``, ``, } { got := strings.ToLower(Description(in)) for _, bad := range []string{"`, ``}, {`x`, `x`}, {`x`, `x`}, {`x`, `x`}, } { if got := DescriptionWithImages(c.in, rewrite); got != c.want { t.Errorf("DescriptionWithImages(%q)\n got %q\nwant %q", c.in, got, c.want) } } }