Skip to content

Commit 8f0a35f

Browse files
committed
Ensure valid git author names passed in signatures
Fix #5772 - Git author names are not allowed to include `\n` `<` or `>` and must not be empty. Ensure that the name passed in a signature is valid. Signed-off-by: Andrew Thornton <[email protected]>
1 parent f631702 commit 8f0a35f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

models/user.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func (u *User) GetFollowing(page int) ([]*User, error) {
416416
// NewGitSig generates and returns the signature of given user.
417417
func (u *User) NewGitSig() *git.Signature {
418418
return &git.Signature{
419-
Name: u.DisplayName(),
419+
Name: u.GitName(),
420420
Email: u.getEmail(),
421421
When: time.Now(),
422422
}
@@ -629,8 +629,18 @@ func (u *User) GetOrganizations(all bool) error {
629629
// DisplayName returns full name if it's not empty,
630630
// returns username otherwise.
631631
func (u *User) DisplayName() string {
632-
if len(u.FullName) > 0 {
633-
return u.FullName
632+
trimmed := strings.TrimSpace(u.FullName)
633+
if len(trimmed) > 0 {
634+
return trimmed
635+
}
636+
return u.Name
637+
}
638+
639+
// GitName returns a git safe name
640+
func (u *User) GitName() string {
641+
gitName := strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(u.FullName))
642+
if len(gitName) > 0 {
643+
return gitName
634644
}
635645
return u.Name
636646
}

0 commit comments

Comments
 (0)