fix: trim the whitespaces for the search keyword (#893)

This commit is contained in:
Bo-Yi Wu 2017-02-11 12:00:01 +08:00 committed by Lunny Xiao
parent 55f2059f71
commit 3576e1ee73
7 changed files with 14 additions and 11 deletions

View File

@ -5,7 +5,7 @@
package repo package repo
import ( import (
"path" "strings"
api "code.gitea.io/sdk/gitea" api "code.gitea.io/sdk/gitea"
@ -21,7 +21,7 @@ import (
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories // see https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
func Search(ctx *context.APIContext) { func Search(ctx *context.APIContext) {
opts := &models.SearchRepoOptions{ opts := &models.SearchRepoOptions{
Keyword: path.Base(ctx.Query("q")), Keyword: strings.Trim(ctx.Query("q"), " "),
OwnerID: ctx.QueryInt64("uid"), OwnerID: ctx.QueryInt64("uid"),
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")), PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
} }

View File

@ -5,6 +5,8 @@
package user package user
import ( import (
"strings"
"github.com/Unknwon/com" "github.com/Unknwon/com"
api "code.gitea.io/sdk/gitea" api "code.gitea.io/sdk/gitea"
@ -16,7 +18,7 @@ import (
// Search search users // Search search users
func Search(ctx *context.APIContext) { func Search(ctx *context.APIContext) {
opts := &models.SearchUserOptions{ opts := &models.SearchUserOptions{
Keyword: ctx.Query("q"), Keyword: strings.Trim(ctx.Query("q"), " "),
Type: models.UserTypeIndividual, Type: models.UserTypeIndividual,
PageSize: com.StrTo(ctx.Query("limit")).MustInt(), PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
} }

View File

@ -5,12 +5,12 @@
package routers package routers
import ( import (
"bytes"
"fmt" "fmt"
"strings"
"github.com/Unknwon/paginater" "github.com/Unknwon/paginater"
"bytes"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
@ -100,7 +100,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
orderBy = "created_unix DESC" orderBy = "created_unix DESC"
} }
keyword := ctx.Query("q") keyword := strings.Trim(ctx.Query("q"), " ")
if len(keyword) == 0 { if len(keyword) == 0 {
repos, err = opts.Ranger(&models.SearchRepoOptions{ repos, err = opts.Ranger(&models.SearchRepoOptions{
Page: page, Page: page,
@ -199,7 +199,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
orderBy = "id DESC" orderBy = "id DESC"
} }
keyword := ctx.Query("q") keyword := strings.Trim(ctx.Query("q"), " ")
if len(keyword) == 0 { if len(keyword) == 0 {
users, err = opts.Ranger(&models.SearchUserOptions{OrderBy: orderBy, users, err = opts.Ranger(&models.SearchUserOptions{OrderBy: orderBy,
Page: page, Page: page,

View File

@ -7,6 +7,7 @@ package repo
import ( import (
"container/list" "container/list"
"path" "path"
"strings"
"code.gitea.io/git" "code.gitea.io/git"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
@ -106,7 +107,7 @@ func Graph(ctx *context.Context) {
func SearchCommits(ctx *context.Context) { func SearchCommits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true ctx.Data["PageIsCommits"] = true
keyword := ctx.Query("q") keyword := strings.Trim(ctx.Query("q"), " ")
if len(keyword) == 0 { if len(keyword) == 0 {
ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName) ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName)
return return

View File

@ -145,7 +145,7 @@ func Issues(ctx *context.Context) {
milestoneID := ctx.QueryInt64("milestone") milestoneID := ctx.QueryInt64("milestone")
isShowClosed := ctx.Query("state") == "closed" isShowClosed := ctx.Query("state") == "closed"
keyword := ctx.Query("q") keyword := strings.Trim(ctx.Query("q"), " ")
if bytes.Contains([]byte(keyword), []byte{0x00}) { if bytes.Contains([]byte(keyword), []byte{0x00}) {
keyword = "" keyword = ""
} }

View File

@ -40,7 +40,7 @@ func GetNotificationCount(c *context.Context) {
// Notifications is the notifications page // Notifications is the notifications page
func Notifications(c *context.Context) { func Notifications(c *context.Context) {
var ( var (
keyword = c.Query("q") keyword = strings.Trim(c.Query("q"), " ")
status models.NotificationStatus status models.NotificationStatus
page = c.QueryInt("page") page = c.QueryInt("page")
perPage = c.QueryInt("perPage") perPage = c.QueryInt("perPage")

View File

@ -155,7 +155,7 @@ func Profile(ctx *context.Context) {
ctx.Data["SortType"] = "recentupdate" ctx.Data["SortType"] = "recentupdate"
} }
keyword := ctx.Query("q") keyword := strings.Trim(ctx.Query("q"), " ")
ctx.Data["Keyword"] = keyword ctx.Data["Keyword"] = keyword
if len(keyword) == 0 { if len(keyword) == 0 {
var total int var total int