Skip to content

Commit 2bb73fe

Browse files
nickolas360lafriks
nickolas360
authored andcommitted
HTML-escape text READMEs (#4192)
1 parent af57d6a commit 2bb73fe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

routers/repo/view.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ func renderDirectory(ctx *context.Context, treeLink string) {
105105
ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()))
106106
} else {
107107
ctx.Data["IsRenderedHTML"] = true
108-
ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
108+
ctx.Data["FileContent"] = strings.Replace(
109+
gotemplate.HTMLEscapeString(string(buf)), "\n", `<br>`, -1,
110+
)
109111
}
110112
}
111113
}
@@ -208,7 +210,9 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
208210
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
209211
} else if readmeExist {
210212
ctx.Data["IsRenderedHTML"] = true
211-
ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
213+
ctx.Data["FileContent"] = strings.Replace(
214+
gotemplate.HTMLEscapeString(string(buf)), "\n", `<br>`, -1,
215+
)
212216
} else {
213217
// Building code view blocks with line number on server side.
214218
var fileContent string

0 commit comments

Comments
 (0)