docs(pier,seaglass,sunrise,sunscreen,tide): compile README Go examples via src= (quick-261118-qsd)
This commit is contained in:
33
modules/seaglass/example_test.go
Normal file
33
modules/seaglass/example_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user