]> source.dussan.org Git - gitea.git/commitdiff
Escape search query (Backport 1.4) (#3488)
authorJonas Franz <info@jonasfranz.software>
Sun, 11 Feb 2018 19:25:02 +0000 (20:25 +0100)
committerLauris BH <lauris@nix.lv>
Sun, 11 Feb 2018 19:25:02 +0000 (21:25 +0200)
* Escape search query

Signed-off-by: Jonas Franz <info@jonasfranz.de>
(cherry picked from commit 2970889)

* Reordered imports

Signed-off-by: Jonas Franz <info@jonasfranz.de>
modules/templates/helper.go
templates/repo/search.tmpl

index d6be25cebb709119c714ed456e3fcfa83d5c618f..2eac62901fe8f7f1ac4cd3cd1eb4bb6fe5a9a94c 100644 (file)
@@ -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()
index 19a9d4474c4526a14a1b1b03f72b132a3f7eb854..3ddc5de86c986b6ec4232dbdc345b63a29ecd1f5 100644 (file)
@@ -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}}