mirror of
https://github.com/gogs/gogs.git
synced 2026-03-01 01:30:57 +01:00
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package markup_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
. "gogs.io/gogs/internal/markup"
|
|
)
|
|
|
|
func Test_Sanitizer(t *testing.T) {
|
|
NewSanitizer()
|
|
tests := []struct {
|
|
input string
|
|
expVal string
|
|
}{
|
|
// Regular
|
|
{input: `<a onblur="alert(secret)" href="http://www.google.com">Google</a>`, expVal: `<a href="http://www.google.com" rel="nofollow">Google</a>`},
|
|
|
|
// Code highlighting class
|
|
{input: `<code class="random string"></code>`, expVal: `<code></code>`},
|
|
{input: `<code class="language-random ui tab active menu attached animating sidebar following bar center"></code>`, expVal: `<code></code>`},
|
|
{input: `<code class="language-go"></code>`, expVal: `<code class="language-go"></code>`},
|
|
|
|
// Input checkbox
|
|
{input: `<input type="hidden">`, expVal: ``},
|
|
{input: `<input type="checkbox">`, expVal: `<input type="checkbox">`},
|
|
{input: `<input checked disabled autofocus>`, expVal: `<input checked="" disabled="">`},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.input, func(t *testing.T) {
|
|
assert.Equal(t, test.expVal, Sanitize(test.input))
|
|
assert.Equal(t, test.expVal, string(SanitizeBytes([]byte(test.input))))
|
|
})
|
|
}
|
|
}
|