From 6792a71a8140cd2127ff85c53b1ead930c9f5a2b Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 22 Nov 2022 19:32:24 +0000 Subject: [PATCH 1/4] Handle empty author names Although git does expect that author names should be of the form: `NAME ` some users have been able to create commits with: `` Fix #21900 Signed-off-by: Andrew Thornton --- modules/git/signature_gogit.go | 4 +++- modules/git/signature_nogogit.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/git/signature_gogit.go b/modules/git/signature_gogit.go index 6f1c98420d05a..8389cfb711c07 100644 --- a/modules/git/signature_gogit.go +++ b/modules/git/signature_gogit.go @@ -30,7 +30,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 { + sig.Name = string(line[:emailStart-1]) + } emailEnd := bytes.IndexByte(line, '>') sig.Email = string(line[emailStart+1 : emailEnd]) diff --git a/modules/git/signature_nogogit.go b/modules/git/signature_nogogit.go index 07a3b79f1effd..aafb9a50cbe2c 100644 --- a/modules/git/signature_nogogit.go +++ b/modules/git/signature_nogogit.go @@ -51,7 +51,9 @@ func newSignatureFromCommitline(line []byte) (sig *Signature, err error) { return } - sig.Name = string(line[:emailStart-1]) + if emailStart > 0 { + sig.Name = string(line[:emailStart-1]) + } sig.Email = string(line[emailStart+1 : emailEnd]) hasTime := emailEnd+2 < len(line) From 95cdd59e39a1ff5bf963d58c601e09fa0ae09ac5 Mon Sep 17 00:00:00 2001 From: zeripath Date: Tue, 22 Nov 2022 21:08:22 +0000 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: delvh --- modules/git/signature_gogit.go | 2 +- modules/git/signature_nogogit.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/git/signature_gogit.go b/modules/git/signature_gogit.go index 8389cfb711c07..fbcf77ba8d173 100644 --- a/modules/git/signature_gogit.go +++ b/modules/git/signature_gogit.go @@ -30,7 +30,7 @@ type Signature = object.Signature func newSignatureFromCommitline(line []byte) (_ *Signature, err error) { sig := new(Signature) emailStart := bytes.IndexByte(line, '<') - if emailStart > 0 { + if emailStart > 0 { // Empty name has already occurred, even if it shouldn't sig.Name = string(line[:emailStart-1]) } emailEnd := bytes.IndexByte(line, '>') diff --git a/modules/git/signature_nogogit.go b/modules/git/signature_nogogit.go index aafb9a50cbe2c..6c4112e09a32b 100644 --- a/modules/git/signature_nogogit.go +++ b/modules/git/signature_nogogit.go @@ -51,7 +51,7 @@ func newSignatureFromCommitline(line []byte) (sig *Signature, err error) { return } - if emailStart > 0 { + if emailStart > 0 { // Empty name has already occurred, even if it shouldn't sig.Name = string(line[:emailStart-1]) } sig.Email = string(line[emailStart+1 : emailEnd]) From 38a8a6edbfba8ff0f503f18b70a00fa3f0ba28c5 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 23 Nov 2022 08:48:33 +0800 Subject: [PATCH 3/4] Apply suggestions from code review --- modules/git/signature_gogit.go | 2 +- modules/git/signature_nogogit.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/git/signature_gogit.go b/modules/git/signature_gogit.go index fbcf77ba8d173..19286fcf238d8 100644 --- a/modules/git/signature_gogit.go +++ b/modules/git/signature_gogit.go @@ -31,7 +31,7 @@ func newSignatureFromCommitline(line []byte) (_ *Signature, err error) { sig := new(Signature) emailStart := bytes.IndexByte(line, '<') if emailStart > 0 { // Empty name has already occurred, even if it shouldn't - sig.Name = string(line[:emailStart-1]) + sig.Name = strings.TrimSpace(string(line[:emailStart-1])) } emailEnd := bytes.IndexByte(line, '>') sig.Email = string(line[emailStart+1 : emailEnd]) diff --git a/modules/git/signature_nogogit.go b/modules/git/signature_nogogit.go index 6c4112e09a32b..1317a8d6ecc71 100644 --- a/modules/git/signature_nogogit.go +++ b/modules/git/signature_nogogit.go @@ -52,7 +52,7 @@ func newSignatureFromCommitline(line []byte) (sig *Signature, err error) { } if emailStart > 0 { // Empty name has already occurred, even if it shouldn't - sig.Name = string(line[:emailStart-1]) + sig.Name = strings.TrimSpace(string(line[:emailStart-1])) } sig.Email = string(line[emailStart+1 : emailEnd]) From 3e88ad1f0ce5e4c76b3ef0855e59e7ca0621cf4f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 23 Nov 2022 08:51:41 +0800 Subject: [PATCH 4/4] Fix import --- modules/git/signature_gogit.go | 1 + modules/git/signature_nogogit.go | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/git/signature_gogit.go b/modules/git/signature_gogit.go index 19286fcf238d8..5ab38cd85252a 100644 --- a/modules/git/signature_gogit.go +++ b/modules/git/signature_gogit.go @@ -10,6 +10,7 @@ package git import ( "bytes" "strconv" + "strings" "time" "github.com/go-git/go-git/v5/plumbing/object" diff --git a/modules/git/signature_nogogit.go b/modules/git/signature_nogogit.go index 1317a8d6ecc71..3fa5c8da3e86e 100644 --- a/modules/git/signature_nogogit.go +++ b/modules/git/signature_nogogit.go @@ -11,6 +11,7 @@ import ( "bytes" "fmt" "strconv" + "strings" "time" )