Skip to content

Commit

Permalink
Handle empty author names (go-gitea#21902)
Browse files Browse the repository at this point in the history
Although git does expect that author names should be of the form: `NAME
<EMAIL>` some users have been able to create commits with: `<EMAIL>`

Fix go-gitea#21900

Signed-off-by: Andrew Thornton <[email protected]>
Co-authored-by: delvh <[email protected]>
Co-authored-by: Lauris BH <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
  • Loading branch information
4 people authored Nov 23, 2022
1 parent ee21d54 commit 4d42cbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion modules/git/signature_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package git
import (
"bytes"
"strconv"
"strings"
"time"

"github.com/go-git/go-git/v5/plumbing/object"
Expand All @@ -30,7 +31,9 @@ type Signature = object.Signature
func newSignatureFromCommitline(line []byte) (_ *Signature, err error) {
sig := new(Signature)
emailStart := bytes.IndexByte(line, '<')
sig.Name = string(line[:emailStart-1])
if emailStart > 0 { // Empty name has already occurred, even if it shouldn't
sig.Name = strings.TrimSpace(string(line[:emailStart-1]))
}
emailEnd := bytes.IndexByte(line, '>')
sig.Email = string(line[emailStart+1 : emailEnd])

Expand Down
5 changes: 4 additions & 1 deletion modules/git/signature_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"bytes"
"fmt"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -51,7 +52,9 @@ func newSignatureFromCommitline(line []byte) (sig *Signature, err error) {
return
}

sig.Name = string(line[:emailStart-1])
if emailStart > 0 { // Empty name has already occurred, even if it shouldn't
sig.Name = strings.TrimSpace(string(line[:emailStart-1]))
}
sig.Email = string(line[emailStart+1 : emailEnd])

hasTime := emailEnd+2 < len(line)
Expand Down

0 comments on commit 4d42cbb

Please sign in to comment.