Skip to content

Commit

Permalink
test(sanitizer): add a fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin authored Jan 12, 2025
1 parent e540547 commit f116f7d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/reader/sanitizer/sanitizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f116f7d

Please sign in to comment.