Skip to content

Commit 13a252d

Browse files
committed
Handle empty author names (go-gitea#21902)
Backport go-gitea#21902 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 <art27@cantab.net>
1 parent 82d50af commit 13a252d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Diff for: modules/git/signature_gogit.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package git
1010
import (
1111
"bytes"
1212
"strconv"
13+
"strings"
1314
"time"
1415

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

Diff for: modules/git/signature_nogogit.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"bytes"
1212
"fmt"
1313
"strconv"
14+
"strings"
1415
"time"
1516
)
1617

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

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

5760
hasTime := emailEnd+2 < len(line)

0 commit comments

Comments
 (0)