From 76f8dc38e7adbce214e4d27c8f1a0ba746492065 Mon Sep 17 00:00:00 2001 From: Yunus Ozen <94426948+ozenyunus35@users.noreply.github.com> Date: Wed, 14 Oct 2026 19:29:38 +0300 Subject: [PATCH] fix(user): don't match a commit with an empty author email to a user (#39777) Fixes https://github.com/go-gitea/gitea/issues/39776 --- models/user/user.go | 3 +++ models/user/user_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/models/user/user.go b/models/user/user.go index 674195400d0..869b31d5d28 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -1231,6 +1231,9 @@ func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, erro noReplyAddressSuffix := "@" + strings.ToLower(setting.Service.NoReplyAddress) for _, email := range emails { emailLower := strings.ToLower(email) + if emailLower == "" { + continue // a commit without an author email names no user + } needCheckEmails.Add(emailLower) if localPart, ok := strings.CutSuffix(emailLower, noReplyAddressSuffix); ok { name, id := parseLocalPartToNameID(localPart) diff --git a/models/user/user_test.go b/models/user/user_test.go index cca2d0192a1..92c344435f2 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -96,6 +96,12 @@ func TestUserEmails(t *testing.T) { setting.Service.NoReplyAddress = "example.com" testGetUserByEmail(t, "user1-2@example.COM", 1) }) + + t.Run("EmptyEmail", func(t *testing.T) { + // A user whose email address is empty must not own commits that have no author email. + require.NoError(t, db.Insert(t.Context(), &user_model.EmailAddress{UID: 2, Email: "", LowerEmail: "", IsActivated: true})) + testGetUserByEmail(t, "", 0) + }) }) t.Run("GetUserByEmail", func(t *testing.T) { testGetUserByEmail := func(t *testing.T, email string, uid int64) {