Explorar o código

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
Julien Voisin hai 1 ano
pai
achega
bfb429b919
Modificáronse 1 ficheiros con 3 adicións e 3 borrados
  1. 3 3
      internal/reader/sanitizer/strip_tags.go

+ 3 - 3
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 {