Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trim the whitespaces for the search keyword #893

Merged
merged 1 commit into from
Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package repo

import (
"path"
"strings"

api "code.gitea.io/sdk/gitea"

Expand All @@ -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")),
}
Expand Down
4 changes: 3 additions & 1 deletion routers/api/v1/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package user

import (
"strings"

"github.com/Unknwon/com"

api "code.gitea.io/sdk/gitea"
Expand All @@ -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(),
}
Expand Down
8 changes: 4 additions & 4 deletions routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion routers/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package repo
import (
"container/list"
"path"
"strings"

"code.gitea.io/git"
"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
Expand Down
2 changes: 1 addition & 1 deletion routers/user/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion routers/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down