]> source.dussan.org Git - gitea.git/commitdiff
fix: trim the whitespaces for the search keyword (#893)
authorBo-Yi Wu <appleboy.tw@gmail.com>
Sat, 11 Feb 2017 04:00:01 +0000 (12:00 +0800)
committerLunny Xiao <xiaolunwen@gmail.com>
Sat, 11 Feb 2017 04:00:01 +0000 (12:00 +0800)
routers/api/v1/repo/repo.go
routers/api/v1/user/user.go
routers/home.go
routers/repo/commit.go
routers/repo/issue.go
routers/user/notification.go
routers/user/profile.go

index 02c017243e4722a24a126e6f2b2942b97871633d..cbcc10a4d4c5f963ee91e5dbd48c19c6660081fe 100644 (file)
@@ -5,7 +5,7 @@
 package repo
 
 import (
-       "path"
+       "strings"
 
        api "code.gitea.io/sdk/gitea"
 
@@ -21,7 +21,7 @@ import (
 // see https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
 func Search(ctx *context.APIContext) {
        opts := &models.SearchRepoOptions{
-               Keyword:  path.Base(ctx.Query("q")),
+               Keyword:  strings.Trim(ctx.Query("q"), " "),
                OwnerID:  ctx.QueryInt64("uid"),
                PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
        }
index 20ed180ef7cbaa5a49605e7162a9438e6ef99f7c..de99fade4660038a915c2b5f1bb59764ecb13114 100644 (file)
@@ -5,6 +5,8 @@
 package user
 
 import (
+       "strings"
+
        "github.com/Unknwon/com"
 
        api "code.gitea.io/sdk/gitea"
@@ -16,7 +18,7 @@ import (
 // Search search users
 func Search(ctx *context.APIContext) {
        opts := &models.SearchUserOptions{
-               Keyword:  ctx.Query("q"),
+               Keyword:  strings.Trim(ctx.Query("q"), " "),
                Type:     models.UserTypeIndividual,
                PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
        }
index f5172182d56d1e9b8b708ddb995b10ce6fc29b72..6f211f4f62c25e5008a600067ebf154123b79d7f 100644 (file)
@@ -5,12 +5,12 @@
 package routers
 
 import (
+       "bytes"
        "fmt"
+       "strings"
 
        "github.com/Unknwon/paginater"
 
-       "bytes"
-
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/context"
@@ -100,7 +100,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
                orderBy = "created_unix DESC"
        }
 
-       keyword := ctx.Query("q")
+       keyword := strings.Trim(ctx.Query("q"), " ")
        if len(keyword) == 0 {
                repos, err = opts.Ranger(&models.SearchRepoOptions{
                        Page:     page,
@@ -199,7 +199,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
                orderBy = "id DESC"
        }
 
-       keyword := ctx.Query("q")
+       keyword := strings.Trim(ctx.Query("q"), " ")
        if len(keyword) == 0 {
                users, err = opts.Ranger(&models.SearchUserOptions{OrderBy: orderBy,
                        Page:     page,
index f165ed8525ba8b45402bda8ec9a3131784107461..37e57ac06f070e18daf4702a0091bb65c4abefbb 100644 (file)
@@ -7,6 +7,7 @@ package repo
 import (
        "container/list"
        "path"
+       "strings"
 
        "code.gitea.io/git"
        "code.gitea.io/gitea/models"
@@ -106,7 +107,7 @@ func Graph(ctx *context.Context) {
 func SearchCommits(ctx *context.Context) {
        ctx.Data["PageIsCommits"] = true
 
-       keyword := ctx.Query("q")
+       keyword := strings.Trim(ctx.Query("q"), " ")
        if len(keyword) == 0 {
                ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName)
                return
index bc9e72a1ac124043e70c5b506eab9fb697130498..17c3b56c2e8db181e1915028f62dbfba6424a2f1 100644 (file)
@@ -145,7 +145,7 @@ func Issues(ctx *context.Context) {
        milestoneID := ctx.QueryInt64("milestone")
        isShowClosed := ctx.Query("state") == "closed"
 
-       keyword := ctx.Query("q")
+       keyword := strings.Trim(ctx.Query("q"), " ")
        if bytes.Contains([]byte(keyword), []byte{0x00}) {
                keyword = ""
        }
index deb98d589c5891aaa48ba746c91438a243c3c21e..77a4a59dc89aa7c8011fa1e9b552c84c2b42e76e 100644 (file)
@@ -40,7 +40,7 @@ func GetNotificationCount(c *context.Context) {
 // Notifications is the notifications page
 func Notifications(c *context.Context) {
        var (
-               keyword = c.Query("q")
+               keyword = strings.Trim(c.Query("q"), " ")
                status  models.NotificationStatus
                page    = c.QueryInt("page")
                perPage = c.QueryInt("perPage")
index cca4391a708482a3fcfdd0c7aca52b781eaafdbe..f0b1be3060ee1a1a4bcfff054ae87416a6676813 100644 (file)
@@ -155,7 +155,7 @@ func Profile(ctx *context.Context) {
                        ctx.Data["SortType"] = "recentupdate"
                }
 
-               keyword := ctx.Query("q")
+               keyword := strings.Trim(ctx.Query("q"), " ")
                ctx.Data["Keyword"] = keyword
                if len(keyword) == 0 {
                        var total int