gitea源码

sanitizer_description_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package markup
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestDescriptionSanitizer(t *testing.T) {
  9. testCases := []string{
  10. `<h1>Title</h1>`, `Title`,
  11. `<img src='img.png' alt='image'>`, ``,
  12. `<span class="emoji" aria-label="thumbs up">THUMBS UP</span>`, `<span class="emoji" aria-label="thumbs up">THUMBS UP</span>`,
  13. `<span style="color: red">Hello World</span>`, `<span>Hello World</span>`,
  14. `<br>`, ``,
  15. `<a href="https://example.com" target="_blank" rel="noopener noreferrer">https://example.com</a>`, `<a href="https://example.com" target="_blank" rel="noopener noreferrer nofollow">https://example.com</a>`,
  16. `<a href="data:1234">data</a>`, `data`,
  17. `<mark>Important!</mark>`, `Important!`,
  18. `<details>Click me! <summary>Nothing to see here.</summary></details>`, `Click me! Nothing to see here.`,
  19. `<input type="hidden">`, ``,
  20. `<b>I</b> have a <i>strong</i> <strong>opinion</strong> about <em>this</em>.`, `<b>I</b> have a <i>strong</i> <strong>opinion</strong> about <em>this</em>.`,
  21. `Provides alternative <code>wg(8)</code> tool`, `Provides alternative <code>wg(8)</code> tool`,
  22. }
  23. for i := 0; i < len(testCases); i += 2 {
  24. assert.Equal(t, testCases[i+1], SanitizeDescription(testCases[i]))
  25. }
  26. }