fix(git): parse co-author trailers that are not RFC 5322 addresses (#39076)

Bot co-authors like `dependabot[bot]` render as one long string with the
email inside the name, and never get truncated, so they overflow the
column.

Co-author idents are parsed with `net/mail`, but a git ident isn't an
email address. `mail.ParseAddress` rejects the whole value when the name
holds characters RFC 5322 reserves, like a `[bot]` suffix or a comma, so
the error branch keeps the raw trailer as the display name and throws
the address away. No address means no `mailto:` link, and the anchor is
what `.avatar-stack-names` truncates.

So parse the angle-addr ourselves when `net/mail` won't take it.
Splitting on the last `<` is safe because git strips angle brackets from
idents. The bare-name branch gets the class too.

Fixes https://github.com/go-gitea/gitea/issues/38949
This commit is contained in:
Artem Lytkin
2026-08-24 22:06:30 +03:00
committed by GitHub
parent 6b929ccb15
commit 2a17cf7ded
4 changed files with 26 additions and 6 deletions
+11
View File
@@ -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 <j@m.com>"},
},
[]*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)