From bfb429b919f8dc2b743a80075e68b56b4fee8610 Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Sun, 8 Dec 2024 00:31:48 +0000 Subject: [PATCH] refactor(sanitizer): optimize `internal/reader/sanitizer/strip_tags.go` - Use strings instead of doing string->bytes->string - Use a strings.Builder to build the output --- internal/reader/sanitizer/strip_tags.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/reader/sanitizer/strip_tags.go b/internal/reader/sanitizer/strip_tags.go index a9f898d8..2da7f5b2 100644 --- a/internal/reader/sanitizer/strip_tags.go +++ b/internal/reader/sanitizer/strip_tags.go @@ -4,8 +4,8 @@ package sanitizer // import "miniflux.app/v2/internal/reader/sanitizer" import ( - "bytes" "io" + "strings" "golang.org/x/net/html" ) @@ -13,8 +13,8 @@ import ( // StripTags removes all HTML/XML tags from the input string. // This function must *only* be used for cosmetic purposes, not to prevent code injections like XSS. func StripTags(input string) string { - tokenizer := html.NewTokenizer(bytes.NewBufferString(input)) - var buffer bytes.Buffer + tokenizer := html.NewTokenizer(strings.NewReader(input)) + var buffer strings.Builder for { if tokenizer.Next() == html.ErrorToken {