diff --git a/modules/git/commit_message.go b/modules/git/commit_message.go index ce82a88ea00..fb9b30bdda2 100644 --- a/modules/git/commit_message.go +++ b/modules/git/commit_message.go @@ -171,16 +171,24 @@ func (c *Commit) AllAuthorIdentities() []*CommitIdentity { addAuthor(c.Author.Name, c.Author.Email, commitIdentityRoleAuthor) for _, coAuthorValue := range trailerCoAuthors { - addr, err := mail.ParseAddress(coAuthorValue) - coAuthorName, coAuthorEmail := coAuthorValue, "" - if err == nil { - coAuthorName, coAuthorEmail = addr.Name, addr.Address - } + coAuthorName, coAuthorEmail := parseCommitIdentityValue(coAuthorValue) addAuthor(coAuthorName, coAuthorEmail, commitIdentityRoleCoAuthor) } return c.allAuthors } +// Git identities are not RFC 5322 addresses: net/mail rejects names like "dependabot[bot]", so fall back to the angle-addr. +func parseCommitIdentityValue(value string) (name, email string) { + if addr, err := mail.ParseAddress(value); err == nil { + return addr.Name, addr.Address + } + begin, end := strings.LastIndex(value, "<"), strings.LastIndex(value, ">") + if begin == -1 || end < begin { + return value, "" + } + return strings.TrimSpace(value[:begin]), strings.TrimSpace(value[begin+1 : end]) +} + func (c *Commit) CoAuthorIdentities() (coAuthors []*CommitIdentity) { all := c.AllAuthorIdentities() if len(all) == 0 { diff --git a/modules/git/commit_message_test.go b/modules/git/commit_message_test.go index 94c0317efc4..649f6fbfeb1 100644 --- a/modules/git/commit_message_test.go +++ b/modules/git/commit_message_test.go @@ -126,6 +126,17 @@ func TestCommitMessageParticipants(t *testing.T) { }, []*CommitIdentity{idt("b", "", roleCoAuthor), idt("c", "", roleCoAuthor)}, }, + { + "CoAuthorNameNotAnEmailAddress", // names net/mail rejects, e.g. bots and names with a comma + &Commit{ + Author: sig("a", "a@m.com"), Committer: sig("c", "c@m.com"), + CommitMessage: CommitMessage{MessageRaw: "Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>\nCo-authored-by: Smith, John "}, + }, + []*CommitIdentity{ + idt("dependabot[bot]", "49699333+dependabot[bot]@users.noreply.github.com", roleCoAuthor), + idt("Smith, John", "j@m.com", roleCoAuthor), + }, + }, } for _, c := range cases { assert.Equal(t, c.identities, c.commit.CoAuthorIdentities(), "case: %s", c.name) diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index f4a7b498323..6c34496e873 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -415,7 +415,7 @@ func (ut *RenderUtils) participantNameLink(data *user_model.AvatarStackData, par if participant.GitIdentity.Email != "" { return htmlutil.HTMLFormat(`%s`, participant.GitIdentity.Email, participant.GitIdentity.Name) } - return template.HTML(template.HTMLEscapeString(participant.GitIdentity.Name)) + return htmlutil.HTMLFormat(`%s`, participant.GitIdentity.Name) } func (ut *RenderUtils) participantPopupRow(data *user_model.AvatarStackData, participant *user_model.CommitParticipant) template.HTML { diff --git a/web_src/css/avatar.css b/web_src/css/avatar.css index 3b34b8207f4..d91fd6a3552 100644 --- a/web_src/css/avatar.css +++ b/web_src/css/avatar.css @@ -16,6 +16,7 @@ img.ui.avatar, } .avatar-stack-names > a.muted, +.avatar-stack-names > .avatar-stack-name, .avatar-stack-names > .avatar-stack-popup-trigger { overflow: hidden; text-overflow: ellipsis;