Skip to content

Commit bd06fdc

Browse files
committed
use FormTrim if posible
1 parent 2d25b7d commit bd06fdc

File tree

18 files changed

+26
-37
lines changed

18 files changed

+26
-37
lines changed

routers/api/v1/notify/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
171171
// "$ref": "#/responses/empty"
172172

173173
lastRead := int64(0)
174-
qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ")
174+
qLastRead := ctx.FormTrim("last_read_at")
175175
if len(qLastRead) > 0 {
176176
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
177177
if err != nil {

routers/api/v1/notify/user.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package notify
66

77
import (
88
"net/http"
9-
"strings"
109
"time"
1110

1211
"code.gitea.io/gitea/models"
@@ -122,7 +121,7 @@ func ReadNotifications(ctx *context.APIContext) {
122121
// "$ref": "#/responses/empty"
123122

124123
lastRead := int64(0)
125-
qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ")
124+
qLastRead := ctx.FormTrim("last_read_at")
126125
if len(qLastRead) > 0 {
127126
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
128127
if err != nil {

routers/api/v1/org/team.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package org
88
import (
99
"fmt"
1010
"net/http"
11-
"strings"
1211

1312
"code.gitea.io/gitea/models"
1413
"code.gitea.io/gitea/modules/context"
@@ -658,7 +657,7 @@ func SearchTeam(ctx *context.APIContext) {
658657

659658
opts := &models.SearchTeamOptions{
660659
UserID: ctx.User.ID,
661-
Keyword: strings.TrimSpace(ctx.FormString("q")),
660+
Keyword: ctx.FormTrim("q"),
662661
OrgID: ctx.Org.Organization.ID,
663662
IncludeDesc: ctx.FormString("include_desc") == "" || ctx.FormBool("include_desc"),
664663
ListOptions: listOptions,

routers/api/v1/repo/issue.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func SearchIssues(ctx *context.APIContext) {
140140
var issues []*models.Issue
141141
var filteredCount int64
142142

143-
keyword := strings.Trim(ctx.FormString("q"), " ")
143+
keyword := ctx.FormTrim("q")
144144
if strings.IndexByte(keyword, 0) >= 0 {
145145
keyword = ""
146146
}
@@ -162,13 +162,13 @@ func SearchIssues(ctx *context.APIContext) {
162162
isPull = util.OptionalBoolNone
163163
}
164164

165-
labels := strings.TrimSpace(ctx.FormString("labels"))
165+
labels := ctx.FormTrim("labels")
166166
var includedLabelNames []string
167167
if len(labels) > 0 {
168168
includedLabelNames = strings.Split(labels, ",")
169169
}
170170

171-
milestones := strings.TrimSpace(ctx.FormString("milestones"))
171+
milestones := ctx.FormTrim("milestones")
172172
var includedMilestones []string
173173
if len(milestones) > 0 {
174174
includedMilestones = strings.Split(milestones, ",")
@@ -331,7 +331,7 @@ func ListIssues(ctx *context.APIContext) {
331331
var issues []*models.Issue
332332
var filteredCount int64
333333

334-
keyword := strings.Trim(ctx.FormString("q"), " ")
334+
keyword := ctx.FormTrim("q")
335335
if strings.IndexByte(keyword, 0) >= 0 {
336336
keyword = ""
337337
}

routers/api/v1/repo/issue_tracked_time.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package repo
77
import (
88
"fmt"
99
"net/http"
10-
"strings"
1110
"time"
1211

1312
"code.gitea.io/gitea/models"
@@ -90,7 +89,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
9089
IssueID: issue.ID,
9190
}
9291

93-
qUser := strings.Trim(ctx.FormString("user"), " ")
92+
qUser := ctx.FormTrim("user")
9493
if qUser != "" {
9594
user, err := models.GetUserByName(qUser)
9695
if models.IsErrUserNotExist(err) {
@@ -500,7 +499,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
500499
}
501500

502501
// Filters
503-
qUser := strings.Trim(ctx.FormString("user"), " ")
502+
qUser := ctx.FormTrim("user")
504503
if qUser != "" {
505504
user, err := models.GetUserByName(qUser)
506505
if models.IsErrUserNotExist(err) {

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func Search(ctx *context.APIContext) {
135135
opts := &models.SearchRepoOptions{
136136
ListOptions: utils.GetListOptions(ctx),
137137
Actor: ctx.User,
138-
Keyword: strings.Trim(ctx.FormString("q"), " "),
138+
Keyword: ctx.FormTrim("q"),
139139
OwnerID: ctx.FormInt64("uid"),
140140
PriorityOwnerID: ctx.FormInt64("priority_owner_id"),
141141
TeamID: ctx.FormInt64("team_id"),

routers/api/v1/user/user.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package user
88
import (
99
"fmt"
1010
"net/http"
11-
"strings"
1211

1312
"code.gitea.io/gitea/models"
1413
"code.gitea.io/gitea/modules/context"
@@ -58,7 +57,7 @@ func Search(ctx *context.APIContext) {
5857

5958
opts := &models.SearchUserOptions{
6059
Actor: ctx.User,
61-
Keyword: strings.Trim(ctx.FormString("q"), " "),
60+
Keyword: ctx.FormTrim("q"),
6261
UID: ctx.FormInt64("uid"),
6362
Type: models.UserTypeIndividual,
6463
ListOptions: listOptions,

routers/web/explore/code.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package explore
66

77
import (
88
"net/http"
9-
"strings"
109

1110
"code.gitea.io/gitea/models"
1211
"code.gitea.io/gitea/modules/base"
@@ -33,14 +32,14 @@ func Code(ctx *context.Context) {
3332
ctx.Data["PageIsExplore"] = true
3433
ctx.Data["PageIsExploreCode"] = true
3534

36-
language := strings.TrimSpace(ctx.FormString("l"))
37-
keyword := strings.TrimSpace(ctx.FormString("q"))
35+
language := ctx.FormTrim("l")
36+
keyword := ctx.FormTrim("q")
3837
page := ctx.FormInt("page")
3938
if page <= 0 {
4039
page = 1
4140
}
4241

43-
queryType := strings.TrimSpace(ctx.FormString("t"))
42+
queryType := ctx.FormTrim("t")
4443
isMatch := queryType == "match"
4544

4645
var (

routers/web/explore/repo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package explore
66

77
import (
88
"net/http"
9-
"strings"
109

1110
"code.gitea.io/gitea/models"
1211
"code.gitea.io/gitea/modules/base"
@@ -73,7 +72,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
7372
orderBy = models.SearchOrderByRecentUpdated
7473
}
7574

76-
keyword := strings.Trim(ctx.FormString("q"), " ")
75+
keyword := ctx.FormTrim("q")
7776
topicOnly := ctx.FormBool("topic")
7877
ctx.Data["TopicOnly"] = topicOnly
7978

routers/web/explore/user.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package explore
77
import (
88
"bytes"
99
"net/http"
10-
"strings"
1110

1211
"code.gitea.io/gitea/models"
1312
"code.gitea.io/gitea/modules/base"
@@ -63,7 +62,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
6362
orderBy = models.SearchOrderByAlphabetically
6463
}
6564

66-
opts.Keyword = strings.Trim(ctx.FormString("q"), " ")
65+
opts.Keyword = ctx.FormTrim("q")
6766
opts.OrderBy = orderBy
6867
if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) {
6968
users, count, err = models.SearchUsers(opts)

routers/web/org/home.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package org
66

77
import (
88
"net/http"
9-
"strings"
109

1110
"code.gitea.io/gitea/models"
1211
"code.gitea.io/gitea/modules/base"
@@ -78,7 +77,7 @@ func Home(ctx *context.Context) {
7877
orderBy = models.SearchOrderByRecentUpdated
7978
}
8079

81-
keyword := strings.Trim(ctx.FormString("q"), " ")
80+
keyword := ctx.FormTrim("q")
8281
ctx.Data["Keyword"] = keyword
8382

8483
page := ctx.FormInt("page")

routers/web/repo/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func SearchCommits(ctx *context.Context) {
177177
ctx.Data["PageIsCommits"] = true
178178
ctx.Data["PageIsViewCode"] = true
179179

180-
query := strings.Trim(ctx.FormString("q"), " ")
180+
query := ctx.FormTrim("q")
181181
if len(query) == 0 {
182182
ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchNameSubURL())
183183
return

routers/web/repo/milestone.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package repo
66

77
import (
88
"net/http"
9-
"strings"
109
"time"
1110

1211
"code.gitea.io/gitea/models"
@@ -47,7 +46,7 @@ func Milestones(ctx *context.Context) {
4746

4847
sortType := ctx.FormString("sort")
4948

50-
keyword := strings.Trim(ctx.FormString("q"), " ")
49+
keyword := ctx.FormTrim("q")
5150

5251
page := ctx.FormInt("page")
5352
if page <= 1 {

routers/web/repo/search.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package repo
66

77
import (
88
"net/http"
9-
"strings"
109

1110
"code.gitea.io/gitea/modules/base"
1211
"code.gitea.io/gitea/modules/context"
@@ -22,13 +21,13 @@ func Search(ctx *context.Context) {
2221
ctx.Redirect(ctx.Repo.RepoLink, 302)
2322
return
2423
}
25-
language := strings.TrimSpace(ctx.FormString("l"))
26-
keyword := strings.TrimSpace(ctx.FormString("q"))
24+
language := ctx.FormTrim("l")
25+
keyword := ctx.FormTrim("q")
2726
page := ctx.FormInt("page")
2827
if page <= 0 {
2928
page = 1
3029
}
31-
queryType := strings.TrimSpace(ctx.FormString("t"))
30+
queryType := ctx.FormTrim("t")
3231
isMatch := queryType == "match"
3332

3433
total, searchResults, searchResultLanguages, err := code_indexer.PerformSearch([]int64{ctx.Repo.Repository.ID},

routers/web/repo/topic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TopicsPost(ctx *context.Context) {
2323
}
2424

2525
var topics = make([]string, 0)
26-
var topicsStr = strings.TrimSpace(ctx.FormString("topics"))
26+
var topicsStr = ctx.FormTrim("topics")
2727
if len(topicsStr) > 0 {
2828
topics = strings.Split(topicsStr, ",")
2929
}

routers/web/user/home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func Milestones(ctx *context.Context) {
204204
isShowClosed = ctx.FormString("state") == "closed"
205205
sortType = ctx.FormString("sort")
206206
page = ctx.FormInt("page")
207-
keyword = strings.Trim(ctx.FormString("q"), " ")
207+
keyword = ctx.FormTrim("q")
208208
)
209209

210210
if page <= 1 {

routers/web/user/notification.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11-
"strconv"
1211
"strings"
1312

1413
"code.gitea.io/gitea/models"
@@ -59,7 +58,7 @@ func Notifications(c *context.Context) {
5958

6059
func getNotifications(c *context.Context) {
6160
var (
62-
keyword = strings.Trim(c.FormString("q"), " ")
61+
keyword = c.FormTrim("q")
6362
status models.NotificationStatus
6463
page = c.FormInt("page")
6564
perPage = c.FormInt("perPage")

routers/web/user/profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func Profile(ctx *context.Context) {
187187
orderBy = models.SearchOrderByRecentUpdated
188188
}
189189

190-
keyword := strings.Trim(ctx.FormString("q"), " ")
190+
keyword := ctx.FormTrim("q")
191191
ctx.Data["Keyword"] = keyword
192192
switch tab {
193193
case "followers":

0 commit comments

Comments
 (0)