Skip to content

Commit ed27da4

Browse files
jonasfranzlafriks
authored andcommitted
Escape search query (Backport 1.3) (#3489)
* Escape search query Signed-off-by: Jonas Franz <[email protected]> (cherry picked from commit 2970889) * Reordered imports Signed-off-by: Jonas Franz <[email protected]>
1 parent 88c363f commit ed27da4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

modules/templates/helper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"container/list"
1010
"encoding/json"
1111
"fmt"
12+
"html"
1213
"html/template"
1314
"mime"
1415
"path/filepath"
@@ -162,6 +163,7 @@ func NewFuncMap() []template.FuncMap {
162163
"UnescapeLocale": func(str string) string {
163164
return strings.NewReplacer("\\;", ";", "\\#", "#").Replace(str)
164165
},
166+
"Escape": Escape,
165167
}}
166168
}
167169

@@ -180,6 +182,11 @@ func Str2html(raw string) template.HTML {
180182
return template.HTML(markup.Sanitize(raw))
181183
}
182184

185+
// Escape escapes a HTML string
186+
func Escape(raw string) string {
187+
return html.EscapeString(raw)
188+
}
189+
183190
// List traversings the list
184191
func List(l *list.List) chan interface{} {
185192
e := l.Front()

templates/repo/search.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</div>
1515
{{if .Keyword}}
1616
<h3>
17-
{{.i18n.Tr "repo.search.results" .Keyword .RepoLink .RepoName | Str2html}}
17+
{{.i18n.Tr "repo.search.results" (.Keyword|Escape) .RepoLink .RepoName | Str2html }}
1818
</h3>
1919
<div class="repository search">
2020
{{range $result := .SearchResults}}

0 commit comments

Comments
 (0)