Skip to content

Commit 3e8285b

Browse files
authored
Use multi reader instead to concat strings (#22099)
extract from #20326
1 parent 352a50d commit 3e8285b

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Diff for: modules/markup/html.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,15 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
305305
return err
306306
}
307307

308-
res := bytes.NewBuffer(make([]byte, 0, len(rawHTML)+50))
309-
// prepend "<html><body>"
310-
_, _ = res.WriteString("<html><body>")
311-
312-
// Strip out nuls - they're always invalid
313-
_, _ = res.Write(tagCleaner.ReplaceAll([]byte(nulCleaner.Replace(string(rawHTML))), []byte("&lt;$1")))
314-
315-
// close the tags
316-
_, _ = res.WriteString("</body></html>")
317-
318308
// parse the HTML
319-
node, err := html.Parse(res)
309+
node, err := html.Parse(io.MultiReader(
310+
// prepend "<html><body>"
311+
strings.NewReader("<html><body>"),
312+
// Strip out nuls - they're always invalid
313+
bytes.NewReader(tagCleaner.ReplaceAll([]byte(nulCleaner.Replace(string(rawHTML))), []byte("&lt;$1"))),
314+
// close the tags
315+
strings.NewReader("</body></html>"),
316+
))
320317
if err != nil {
321318
return &postProcessError{"invalid HTML", err}
322319
}

0 commit comments

Comments
 (0)