Quellcode durchsuchen

perf(sanitizer): Use an io.MultiReader

This avoids having to copy rawHTML.
jvoisin vor 1 Woche
Ursprung
Commit
21703c81f4
1 geänderte Dateien mit 6 neuen und 1 gelöschten Zeilen
  1. 6 1
      internal/reader/sanitizer/sanitizer.go

+ 6 - 1
internal/reader/sanitizer/sanitizer.go

@@ -5,6 +5,7 @@ package sanitizer // import "miniflux.app/v2/internal/reader/sanitizer"
 
 
 import (
 import (
 	"errors"
 	"errors"
+	"io"
 	"net/url"
 	"net/url"
 	"slices"
 	"slices"
 	"strconv"
 	"strconv"
@@ -223,7 +224,11 @@ func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) s
 
 
 	// We need to surround `rawHTML` with body tags so that html.Parse
 	// We need to surround `rawHTML` with body tags so that html.Parse
 	// will consider it a valid html document.
 	// will consider it a valid html document.
-	doc, err := html.Parse(strings.NewReader("<body>" + rawHTML + "</body>"))
+	doc, err := html.Parse(io.MultiReader(
+		strings.NewReader("<body>"),
+		strings.NewReader(rawHTML),
+		strings.NewReader("</body>"),
+	))
 	if err != nil {
 	if err != nil {
 		return ""
 		return ""
 	}
 	}