99
1010 "github.com/Unknwon/paginater"
1111
12+ "bytes"
13+
1214 "code.gitea.io/gitea/models"
1315 "code.gitea.io/gitea/modules/base"
1416 "code.gitea.io/gitea/modules/context"
@@ -60,6 +62,14 @@ type RepoSearchOptions struct {
6062 TplName base.TplName
6163}
6264
65+ var (
66+ nullByte = []byte {0x00 }
67+ )
68+
69+ func isKeywordValid (keyword string ) bool {
70+ return ! bytes .Contains ([]byte (keyword ), nullByte )
71+ }
72+
6373// RenderRepoSearch render repositories search page
6474func RenderRepoSearch (ctx * context.Context , opts * RepoSearchOptions ) {
6575 page := ctx .QueryInt ("page" )
@@ -82,16 +92,18 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
8292 }
8393 count = opts .Counter (opts .Private )
8494 } else {
85- repos , count , err = models .SearchRepositoryByName (& models.SearchRepoOptions {
86- Keyword : keyword ,
87- OrderBy : opts .OrderBy ,
88- Private : opts .Private ,
89- Page : page ,
90- PageSize : opts .PageSize ,
91- })
92- if err != nil {
93- ctx .Handle (500 , "SearchRepositoryByName" , err )
94- return
95+ if isKeywordValid (keyword ) {
96+ repos , count , err = models .SearchRepositoryByName (& models.SearchRepoOptions {
97+ Keyword : keyword ,
98+ OrderBy : opts .OrderBy ,
99+ Private : opts .Private ,
100+ Page : page ,
101+ PageSize : opts .PageSize ,
102+ })
103+ if err != nil {
104+ ctx .Handle (500 , "SearchRepositoryByName" , err )
105+ return
106+ }
95107 }
96108 }
97109 ctx .Data ["Keyword" ] = keyword
@@ -156,16 +168,18 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
156168 }
157169 count = opts .Counter ()
158170 } else {
159- users , count , err = models .SearchUserByName (& models.SearchUserOptions {
160- Keyword : keyword ,
161- Type : opts .Type ,
162- OrderBy : opts .OrderBy ,
163- Page : page ,
164- PageSize : opts .PageSize ,
165- })
166- if err != nil {
167- ctx .Handle (500 , "SearchUserByName" , err )
168- return
171+ if isKeywordValid (keyword ) {
172+ users , count , err = models .SearchUserByName (& models.SearchUserOptions {
173+ Keyword : keyword ,
174+ Type : opts .Type ,
175+ OrderBy : opts .OrderBy ,
176+ Page : page ,
177+ PageSize : opts .PageSize ,
178+ })
179+ if err != nil {
180+ ctx .Handle (500 , "SearchUserByName" , err )
181+ return
182+ }
169183 }
170184 }
171185 ctx .Data ["Keyword" ] = keyword
0 commit comments