diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-01 18:52:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-01 18:52:57 +0800 |
commit | 590a79ff8a7f8f9eab9dc19ea96dae2083449c70 (patch) | |
tree | 00ff6f38a7b363289a73c6aab2eefc967eda5f16 /routers/home.go | |
parent | 2343feadd434561d86b1273792d88f609a782114 (diff) | |
download | gitea-590a79ff8a7f8f9eab9dc19ea96dae2083449c70.tar.gz gitea-590a79ff8a7f8f9eab9dc19ea96dae2083449c70.zip |
Resolved #296 (#324)
* resolved #296
* Indentation fixed
Diffstat (limited to 'routers/home.go')
-rw-r--r-- | routers/home.go | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/routers/home.go b/routers/home.go index a2faf65bcc..3b51148762 100644 --- a/routers/home.go +++ b/routers/home.go @@ -9,6 +9,8 @@ import ( "github.com/Unknwon/paginater" + "bytes" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -60,6 +62,14 @@ type RepoSearchOptions struct { TplName base.TplName } +var ( + nullByte = []byte{0x00} +) + +func isKeywordValid(keyword string) bool { + return !bytes.Contains([]byte(keyword), nullByte) +} + // RenderRepoSearch render repositories search page func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { page := ctx.QueryInt("page") @@ -82,16 +92,18 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { } count = opts.Counter(opts.Private) } else { - repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ - Keyword: keyword, - OrderBy: opts.OrderBy, - Private: opts.Private, - Page: page, - PageSize: opts.PageSize, - }) - if err != nil { - ctx.Handle(500, "SearchRepositoryByName", err) - return + if isKeywordValid(keyword) { + repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ + Keyword: keyword, + OrderBy: opts.OrderBy, + Private: opts.Private, + Page: page, + PageSize: opts.PageSize, + }) + if err != nil { + ctx.Handle(500, "SearchRepositoryByName", err) + return + } } } ctx.Data["Keyword"] = keyword @@ -156,16 +168,18 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { } count = opts.Counter() } else { - users, count, err = models.SearchUserByName(&models.SearchUserOptions{ - Keyword: keyword, - Type: opts.Type, - OrderBy: opts.OrderBy, - Page: page, - PageSize: opts.PageSize, - }) - if err != nil { - ctx.Handle(500, "SearchUserByName", err) - return + if isKeywordValid(keyword) { + users, count, err = models.SearchUserByName(&models.SearchUserOptions{ + Keyword: keyword, + Type: opts.Type, + OrderBy: opts.OrderBy, + Page: page, + PageSize: opts.PageSize, + }) + if err != nil { + ctx.Handle(500, "SearchUserByName", err) + return + } } } ctx.Data["Keyword"] = keyword |