Skip to content

Commit 67fcd64

Browse files
committed
Account for pathologically named external users
LDAP and the like usernames are not checked in the same way that users who signup are. Therefore just ensure that user names are also git safe and if totally pathological - Set them to "user-$UID" Signed-off-by: Andrew Thornton <[email protected]>
1 parent 8f0a35f commit 67fcd64

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

models/user.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,24 @@ func (u *User) DisplayName() string {
636636
return u.Name
637637
}
638638

639+
func gitSafeName(name string) string {
640+
return strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(name))
641+
}
642+
639643
// GitName returns a git safe name
640644
func (u *User) GitName() string {
641-
gitName := strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(u.FullName))
645+
gitName := gitSafeName(u.FullName)
642646
if len(gitName) > 0 {
643647
return gitName
644648
}
645-
return u.Name
649+
// Although u.Name should be safe if created in our system
650+
// LDAP users may have bad names
651+
gitName = gitSafeName(u.Name)
652+
if len(gitName) > 0 {
653+
return gitName
654+
}
655+
// Totally pathological name so it's got to be:
656+
return fmt.Sprintf("user-%d", u.ID)
646657
}
647658

648659
// ShortName ellipses username to length

0 commit comments

Comments
 (0)