Files
summercms/modules/seaglass/example_test.go

34 lines
802 B
Go

package seaglass_test
import (
"fmt"
"git.golem15.com/golem15/summercms/modules/seaglass"
)
func ExampleSanitizeReport() {
clean, report := seaglass.SanitizeReport(`<p onclick="x()">Hi</p><script>alert(1)</script>`)
fmt.Println(clean)
fmt.Println(report.Elements, report.Attributes, report.Changed)
// Output:
// <p>Hi</p>
// [script] [onclick] true
}
func ExampleCheck() {
for _, stored := range []string{
`<p class="lead">Hi <a href="tel:+48123">call</a></p>`,
`<p><a href="javascript:alert(1)">x</a></p>`,
} {
if err := seaglass.Check(stored); err != nil {
// stored HTML would change under the policy
fmt.Println(err)
continue
}
fmt.Println("kept whole")
}
// Output:
// kept whole
// seaglass: HTML contains elements, attributes or URLs that are not allowed
}