sanitizer_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package markup_test
  2. import (
  3. . "gitote/gitote/pkg/markup"
  4. "testing"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func Test_Sanitizer(t *testing.T) {
  8. NewSanitizer()
  9. Convey("Sanitize HTML string and bytes", t, func() {
  10. testCases := []string{
  11. // Regular
  12. `<a onblur="alert(secret)" href="http://www.google.com">Google</a>`, `<a href="http://www.google.com" rel="nofollow">Google</a>`,
  13. // Code highlighting class
  14. `<code class="random string"></code>`, `<code></code>`,
  15. `<code class="language-random ui tab active menu attached animating sidebar following bar center"></code>`, `<code></code>`,
  16. `<code class="language-go"></code>`, `<code class="language-go"></code>`,
  17. // Input checkbox
  18. `<input type="hidden">`, ``,
  19. `<input type="checkbox">`, `<input type="checkbox">`,
  20. `<input checked disabled autofocus>`, `<input checked="" disabled="">`,
  21. }
  22. for i := 0; i < len(testCases); i += 2 {
  23. So(Sanitize(testCases[i]), ShouldEqual, testCases[i+1])
  24. So(string(SanitizeBytes([]byte(testCases[i]))), ShouldEqual, testCases[i+1])
  25. }
  26. })
  27. }