diff options
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/models/user.go b/models/user.go index 0d8f608861..4ab78ec04e 100644 --- a/models/user.go +++ b/models/user.go @@ -417,7 +417,7 @@ func (u *User) GetFollowing(page int) ([]*User, error) { // NewGitSig generates and returns the signature of given user. func (u *User) NewGitSig() *git.Signature { return &git.Signature{ - Name: u.DisplayName(), + Name: u.GitName(), Email: u.getEmail(), When: time.Now(), } @@ -630,12 +630,33 @@ func (u *User) GetOrganizations(all bool) error { // DisplayName returns full name if it's not empty, // returns username otherwise. func (u *User) DisplayName() string { - if len(u.FullName) > 0 { - return u.FullName + trimmed := strings.TrimSpace(u.FullName) + if len(trimmed) > 0 { + return trimmed } 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 := gitSafeName(u.FullName) + if len(gitName) > 0 { + return gitName + } + // 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 func (u *User) ShortName(length int) string { return base.EllipsisString(u.Name, length) |