sanitizer_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package markup_test
  5. import (
  6. "testing"
  7. . "github.com/smartystreets/goconvey/convey"
  8. . "github.com/gogits/gogs/pkg/markup"
  9. )
  10. func Test_Sanitizer(t *testing.T) {
  11. NewSanitizer()
  12. Convey("Sanitize HTML string and bytes", t, func() {
  13. testCases := []string{
  14. // Regular
  15. `<a onblur="alert(secret)" href="http://www.google.com">Google</a>`, `<a href="http://www.google.com" rel="nofollow">Google</a>`,
  16. // Code highlighting class
  17. `<code class="random string"></code>`, `<code></code>`,
  18. `<code class="language-random ui tab active menu attached animating sidebar following bar center"></code>`, `<code></code>`,
  19. `<code class="language-go"></code>`, `<code class="language-go"></code>`,
  20. // Input checkbox
  21. `<input type="hidden">`, ``,
  22. `<input type="checkbox">`, `<input type="checkbox">`,
  23. `<input checked disabled autofocus>`, `<input checked="" disabled="">`,
  24. }
  25. for i := 0; i < len(testCases); i += 2 {
  26. So(Sanitize(testCases[i]), ShouldEqual, testCases[i+1])
  27. So(string(SanitizeBytes([]byte(testCases[i]))), ShouldEqual, testCases[i+1])
  28. }
  29. })
  30. }