From c0675ef6c29933376bd77b056f55d8e2a788602f Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sun, 11 Feb 2018 20:25:02 +0100 Subject: [PATCH] Escape search query (Backport 1.4) (#3488) * Escape search query Signed-off-by: Jonas Franz (cherry picked from commit 2970889) * Reordered imports Signed-off-by: Jonas Franz --- modules/templates/helper.go | 7 +++++++ templates/repo/search.tmpl | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index d6be25cebb..2eac62901f 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -10,6 +10,7 @@ import ( "encoding/json" "errors" "fmt" + "html" "html/template" "mime" "net/url" @@ -179,6 +180,7 @@ func NewFuncMap() []template.FuncMap { return dict, nil }, "Printf": fmt.Sprintf, + "Escape": Escape, }} } @@ -197,6 +199,11 @@ func Str2html(raw string) template.HTML { return template.HTML(markup.Sanitize(raw)) } +// Escape escapes a HTML string +func Escape(raw string) string { + return html.EscapeString(raw) +} + // List traversings the list func List(l *list.List) chan interface{} { e := l.Front() diff --git a/templates/repo/search.tmpl b/templates/repo/search.tmpl index 19a9d4474c..3ddc5de86c 100644 --- a/templates/repo/search.tmpl +++ b/templates/repo/search.tmpl @@ -14,7 +14,7 @@ {{if .Keyword}}

- {{.i18n.Tr "repo.search.results" .Keyword .RepoLink .RepoName | Str2html}} + {{.i18n.Tr "repo.search.results" (.Keyword|Escape) .RepoLink .RepoName | Str2html }}