Skip to content

Commit

Permalink
Escape search query (#3486)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Franz <info@jonasfranz.de>
  • Loading branch information
jonasfranz authored and lafriks committed Feb 11, 2018
1 parent 6eaeb01 commit 2cb4649
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"golang.org/x/net/html/charset"
"golang.org/x/text/transform"
"gopkg.in/editorconfig/editorconfig-core-go.v1"
"html"
)

// NewFuncMap returns functions for injecting to templates
Expand Down Expand Up @@ -179,6 +180,7 @@ func NewFuncMap() []template.FuncMap {
return dict, nil
},
"Printf": fmt.Sprintf,
"Escape": Escape,
}}
}

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/search.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
{{if .Keyword}}
<h3>
{{.i18n.Tr "repo.search.results" .Keyword .RepoLink .RepoName | Str2html}}
{{.i18n.Tr "repo.search.results" (.Keyword|Escape) .RepoLink .RepoName | Str2html }}
</h3>
<div class="repository search">
{{range $result := .SearchResults}}
Expand Down

0 comments on commit 2cb4649

Please sign in to comment.