File tree 4 files changed +38
-6
lines changed
4 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import (
15
15
"code.gitea.io/gitea/modules/base"
16
16
"code.gitea.io/gitea/modules/context"
17
17
"code.gitea.io/gitea/modules/log"
18
+ "code.gitea.io/gitea/routers/utils"
18
19
)
19
20
20
21
const (
@@ -76,11 +77,7 @@ func TeamsAction(ctx *context.Context) {
76
77
ctx .Error (404 )
77
78
return
78
79
}
79
- uname := ctx .Query ("uname" )
80
- // uname may be formatted as "username (fullname)"
81
- if strings .Contains (uname , "(" ) && strings .HasSuffix (uname , ")" ) {
82
- uname = strings .TrimSpace (strings .Split (uname , "(" )[0 ])
83
- }
80
+ uname := utils .RemoveUsernameParameterSuffix (strings .ToLower (ctx .Query ("uname" )))
84
81
var u * models.User
85
82
u , err = models .GetUserByName (uname )
86
83
if err != nil {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import (
16
16
"code.gitea.io/gitea/modules/context"
17
17
"code.gitea.io/gitea/modules/log"
18
18
"code.gitea.io/gitea/modules/setting"
19
+ "code.gitea.io/gitea/routers/utils"
19
20
)
20
21
21
22
const (
@@ -366,7 +367,7 @@ func Collaboration(ctx *context.Context) {
366
367
367
368
// CollaborationPost response for actions for a collaboration of a repository
368
369
func CollaborationPost (ctx * context.Context ) {
369
- name := strings .ToLower (ctx .Query ("collaborator" ))
370
+ name := utils . RemoveUsernameParameterSuffix ( strings .ToLower (ctx .Query ("collaborator" ) ))
370
371
if len (name ) == 0 || ctx .Repo .Owner .LowerName == name {
371
372
ctx .Redirect (setting .AppSubURL + ctx .Req .URL .Path )
372
373
return
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 The Gitea Authors. All rights reserved.
2
+ // Use of this source code is governed by a MIT-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package utils
6
+
7
+ import (
8
+ "strings"
9
+ )
10
+
11
+ // RemoveUsernameParameterSuffix returns the username parameter without the (fullname) suffix - leaving just the username
12
+ func RemoveUsernameParameterSuffix (name string ) string {
13
+ if index := strings .Index (name , " (" ); index >= 0 {
14
+ name = name [:index ]
15
+ }
16
+ return name
17
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 The Gitea Authors. All rights reserved.
2
+ // Use of this source code is governed by a MIT-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package utils
6
+
7
+ import (
8
+ "testing"
9
+
10
+ "github.com/stretchr/testify/assert"
11
+ )
12
+
13
+ func TestRemoveUsernameParameterSuffix (t * testing.T ) {
14
+ assert .Equal (t , "foobar" , RemoveUsernameParameterSuffix ("foobar (Foo Bar)" ))
15
+ assert .Equal (t , "foobar" , RemoveUsernameParameterSuffix ("foobar" ))
16
+ assert .Equal (t , "" , RemoveUsernameParameterSuffix ("" ))
17
+ }
You can’t perform that action at this time.
0 commit comments