Skip to content

Commit c0675ef

Browse files
jonasfranzlafriks
authored andcommitted
Escape search query (Backport 1.4) (#3488)
* 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 4e27cc4 commit c0675ef

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
@@ -10,6 +10,7 @@ import (
1010
"encoding/json"
1111
"errors"
1212
"fmt"
13+
"html"
1314
"html/template"
1415
"mime"
1516
"net/url"
@@ -179,6 +180,7 @@ func NewFuncMap() []template.FuncMap {
179180
return dict, nil
180181
},
181182
"Printf": fmt.Sprintf,
183+
"Escape": Escape,
182184
}}
183185
}
184186

@@ -197,6 +199,11 @@ func Str2html(raw string) template.HTML {
197199
return template.HTML(markup.Sanitize(raw))
198200
}
199201

202+
// Escape escapes a HTML string
203+
func Escape(raw string) string {
204+
return html.EscapeString(raw)
205+
}
206+
200207
// List traversings the list
201208
func List(l *list.List) chan interface{} {
202209
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)