1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-07-22 17:18:37 +00:00

test(sanitizer): add a fuzzer

This commit is contained in:
Julien Voisin 2025-01-12 01:19:31 +00:00 committed by GitHub
parent e540547104
commit f116f7dd6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,8 +5,11 @@ package sanitizer // import "miniflux.app/v2/internal/reader/sanitizer"
import (
"os"
"strings"
"testing"
"golang.org/x/net/html"
"miniflux.app/v2/internal/config"
)
@ -35,6 +38,28 @@ func BenchmarkSanitize(b *testing.B) {
}
}
func FuzzSanitizer(f *testing.F) {
f.Fuzz(func(t *testing.T, orig string) {
tok := html.NewTokenizer(strings.NewReader(orig))
i := 0
for tok.Next() != html.ErrorToken {
i++
}
out := Sanitize("", orig)
tok = html.NewTokenizer(strings.NewReader(out))
j := 0
for tok.Next() != html.ErrorToken {
j++
}
if j > i {
t.Errorf("Got more html tokens in the sanitized html.")
}
})
}
func TestValidInput(t *testing.T) {
input := `<p>This is a <strong>text</strong> with an image: <img src="http://example.org/" alt="Test" loading="lazy">.</p>`
output := Sanitize("http://example.org/", input)