Skip to content
Merged
Changes from 1 commit
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: 4 additions & 0 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ func Collaboration(ctx *context.Context) {
// CollaborationPost response for actions for a collaboration of a repository
func CollaborationPost(ctx *context.Context) {
name := strings.ToLower(ctx.Query("collaborator"))
// name may be formatted as "username (fullname)"
if strings.Contains(name, "(") && strings.HasSuffix(name, ")") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can simplify to

if index := strings.Index(name, " ("); index >= 0 {
	name = name[:index]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just cut-n-pasted @lunny's fix. I agree with you on this. Where can I put a utility method and then refactor all of the usages? Sorry new to Gitea, so want to make sure I'm following your guys' best practices... Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding a routers/utils/utils.go file and putting it there makes the most sense. This proposed function seems specific to route handlers, so I'd prefer to not add it to modules/util.

name = strings.TrimSpace(strings.Split(name, "(")[0])
}
if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.Path)
return
Expand Down