From 67fcd64fa01eaf636fe18b3da2c73326b5445c07 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 20 Jan 2019 12:06:33 +0000 Subject: [PATCH] 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 --- models/user.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/models/user.go b/models/user.go index f49196e220762..55809dbc332f3 100644 --- a/models/user.go +++ b/models/user.go @@ -636,13 +636,24 @@ func (u *User) DisplayName() string { return u.Name } +func gitSafeName(name string) string { + return strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(name)) +} + // GitName returns a git safe name func (u *User) GitName() string { - gitName := strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(u.FullName)) + gitName := gitSafeName(u.FullName) if len(gitName) > 0 { return gitName } - return u.Name + // Although u.Name should be safe if created in our system + // LDAP users may have bad names + gitName = gitSafeName(u.Name) + if len(gitName) > 0 { + return gitName + } + // Totally pathological name so it's got to be: + return fmt.Sprintf("user-%d", u.ID) } // ShortName ellipses username to length