Skip to content

Commit 2cb4649

Browse files
jonasfranzlafriks
authored andcommitted
Escape search query (#3486)
Signed-off-by: Jonas Franz <[email protected]>
1 parent 6eaeb01 commit 2cb4649

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

modules/templates/helper.go

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"golang.org/x/net/html/charset"
2828
"golang.org/x/text/transform"
2929
"gopkg.in/editorconfig/editorconfig-core-go.v1"
30+
"html"
3031
)
3132

3233
// NewFuncMap returns functions for injecting to templates
@@ -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

+1-1
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)