sanitizer_test.go 1.3 KB

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