code.gitea.io/gitea@v1.22.3/modules/markup/sanitizer_description_test.go (about)

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