Handle empty author names (#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 #21900

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
pull/21901/head^2
zeripath 2 years ago committed by GitHub
parent ee21d5453f
commit 4d42cbbcc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      modules/git/signature_gogit.go
  2. 5
      modules/git/signature_nogogit.go

@ -10,6 +10,7 @@ package git
import ( import (
"bytes" "bytes"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/object"
@ -30,7 +31,9 @@ type Signature = object.Signature
func newSignatureFromCommitline(line []byte) (_ *Signature, err error) { func newSignatureFromCommitline(line []byte) (_ *Signature, err error) {
sig := new(Signature) sig := new(Signature)
emailStart := bytes.IndexByte(line, '<') 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, '>') emailEnd := bytes.IndexByte(line, '>')
sig.Email = string(line[emailStart+1 : emailEnd]) sig.Email = string(line[emailStart+1 : emailEnd])

@ -11,6 +11,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"time" "time"
) )
@ -51,7 +52,9 @@ func newSignatureFromCommitline(line []byte) (sig *Signature, err error) {
return 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]) sig.Email = string(line[emailStart+1 : emailEnd])
hasTime := emailEnd+2 < len(line) hasTime := emailEnd+2 < len(line)

Loading…
Cancel
Save