summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-12-12 11:03:54 +0800
committerGitHub <noreply@github.com>2022-12-12 11:03:54 +0800
commit3e8285b824d77bafa3335765d68a6b499d9faad4 (patch)
tree63e8ddf3e9474858594fe6df9d61f9724e3e070f /modules
parent352a50d65f02e81bb06b07fd6cd11e83f5d64cb0 (diff)
downloadgitea-3e8285b824d77bafa3335765d68a6b499d9faad4.tar.gz
gitea-3e8285b824d77bafa3335765d68a6b499d9faad4.zip
Use multi reader instead to concat strings (#22099)
extract from #20326
Diffstat (limited to 'modules')
-rw-r--r--modules/markup/html.go19
1 files changed, 8 insertions, 11 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index 80b19ba35f..6b5a8e32d4 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -305,18 +305,15 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
return err
}
- res := bytes.NewBuffer(make([]byte, 0, len(rawHTML)+50))
- // prepend "<html><body>"
- _, _ = res.WriteString("<html><body>")
-
- // Strip out nuls - they're always invalid
- _, _ = res.Write(tagCleaner.ReplaceAll([]byte(nulCleaner.Replace(string(rawHTML))), []byte("&lt;$1")))
-
- // close the tags
- _, _ = res.WriteString("</body></html>")
-
// parse the HTML
- node, err := html.Parse(res)
+ node, err := html.Parse(io.MultiReader(
+ // prepend "<html><body>"
+ strings.NewReader("<html><body>"),
+ // Strip out nuls - they're always invalid
+ bytes.NewReader(tagCleaner.ReplaceAll([]byte(nulCleaner.Replace(string(rawHTML))), []byte("&lt;$1"))),
+ // close the tags
+ strings.NewReader("</body></html>"),
+ ))
if err != nil {
return &postProcessError{"invalid HTML", err}
}