File tree Expand file tree Collapse file tree 4 files changed +38
-6
lines changed Expand file tree Collapse file tree 4 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import (
1515 "code.gitea.io/gitea/modules/base"
1616 "code.gitea.io/gitea/modules/context"
1717 "code.gitea.io/gitea/modules/log"
18+ "code.gitea.io/gitea/routers/utils"
1819)
1920
2021const (
@@ -76,11 +77,7 @@ func TeamsAction(ctx *context.Context) {
7677 ctx .Error (404 )
7778 return
7879 }
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" )))
8481 var u * models.User
8582 u , err = models .GetUserByName (uname )
8683 if err != nil {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import (
1616 "code.gitea.io/gitea/modules/context"
1717 "code.gitea.io/gitea/modules/log"
1818 "code.gitea.io/gitea/modules/setting"
19+ "code.gitea.io/gitea/routers/utils"
1920)
2021
2122const (
@@ -366,7 +367,7 @@ func Collaboration(ctx *context.Context) {
366367
367368// CollaborationPost response for actions for a collaboration of a repository
368369func CollaborationPost (ctx * context.Context ) {
369- name := strings .ToLower (ctx .Query ("collaborator" ))
370+ name := utils . RemoveUsernameParameterSuffix ( strings .ToLower (ctx .Query ("collaborator" ) ))
370371 if len (name ) == 0 || ctx .Repo .Owner .LowerName == name {
371372 ctx .Redirect (setting .AppSubURL + ctx .Req .URL .Path )
372373 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