Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 97ba556

Browse files
authored
Merge pull request #158 from RifeWang/master
fix: 搜索异常时导致页面渲染异常, 搜索框 XSS 漏洞
2 parents fdaf70e + 038bce7 commit 97ba556

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

http/controller/search.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controller
22

33
import (
4+
"html"
5+
46
"github.com/studygolang/studygolang/context"
57
"github.com/studygolang/studygolang/logic"
68

@@ -31,11 +33,12 @@ func (SearchController) Search(ctx echo.Context) error {
3133
"q": q,
3234
"f": field,
3335
}
34-
if err == nil {
35-
uri := "/search?q=" + q + "&f=" + field + "&"
36-
paginator := logic.NewPaginatorWithPerPage(p, rows)
37-
data["pageHtml"] = paginator.SetTotal(int64(respBody.NumFound)).GetPageHtml(uri)
36+
if err != nil {
37+
return render(ctx, "500.html", nil)
3838
}
39+
uri := "/search?q=" + html.EscapeString(q) + "&f=" + field + "&"
40+
paginator := logic.NewPaginatorWithPerPage(p, rows)
41+
data["pageHtml"] = paginator.SetTotal(int64(respBody.NumFound)).GetPageHtml(uri)
3942

4043
return render(ctx, "search.html", data)
4144
}
@@ -60,11 +63,12 @@ func (SearchController) TagList(ctx echo.Context) error {
6063
"users": users,
6164
"nodes": nodes,
6265
}
63-
if err == nil {
64-
uri := "/tag/" + q + "?"
65-
paginator := logic.NewPaginatorWithPerPage(p, rows)
66-
data["pageHtml"] = paginator.SetTotal(int64(respBody.NumFound)).GetPageHtml(uri)
66+
if err != nil {
67+
return render(ctx, "500.html", nil)
6768
}
69+
uri := "/tag/" + q + "?"
70+
paginator := logic.NewPaginatorWithPerPage(p, rows)
71+
data["pageHtml"] = paginator.SetTotal(int64(respBody.NumFound)).GetPageHtml(uri)
6872

6973
return render(ctx, "feed/tag.html", data)
7074
}

0 commit comments

Comments
 (0)