diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2024-03-13 11:34:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-13 10:34:58 +0000 |
commit | 85c59d6c21e10ef9d3ccf11713548f50e47e920f (patch) | |
tree | 3d6208785763a7e5aa3b2f5ad47e9fc8032b7f0e /services | |
parent | 66edc888ee8b2f77a6f11139acd2d03c561ad5ef (diff) | |
download | gitea-85c59d6c21e10ef9d3ccf11713548f50e47e920f.tar.gz gitea-85c59d6c21e10ef9d3ccf11713548f50e47e920f.zip |
Use relative links for commits, mentions, and issues in markdown (#29427)
Fixes #29404
Use relative links for
- commits
- mentions
- issues
---------
Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'services')
-rw-r--r-- | services/mailer/mail.go | 3 | ||||
-rw-r--r-- | services/mailer/mail_test.go | 26 |
2 files changed, 27 insertions, 2 deletions
diff --git a/services/mailer/mail.go b/services/mailer/mail.go index 38973ea935..a63ba7a52a 100644 --- a/services/mailer/mail.go +++ b/services/mailer/mail.go @@ -222,7 +222,8 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient body, err := markdown.RenderString(&markup.RenderContext{ Ctx: ctx, Links: markup.Links{ - Base: ctx.Issue.Repo.HTMLURL(), + AbsolutePrefix: true, + Base: ctx.Issue.Repo.HTMLURL(), }, Metas: ctx.Issue.Repo.ComposeMetas(ctx), }, ctx.Content) diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go index e300aeccb0..d87c57ffe7 100644 --- a/services/mailer/mail_test.go +++ b/services/mailer/mail_test.go @@ -8,6 +8,8 @@ import ( "context" "fmt" "html/template" + "io" + "mime/quotedprintable" "regexp" "strings" "testing" @@ -19,6 +21,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" "github.com/stretchr/testify/assert" @@ -67,6 +70,12 @@ func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Re func TestComposeIssueCommentMessage(t *testing.T) { doer, _, issue, comment := prepareMailerTest(t) + markup.Init(&markup.ProcessorHelper{ + IsUsernameMentionable: func(ctx context.Context, username string) bool { + return username == doer.Name + }, + }) + setting.IncomingEmail.Enabled = true defer func() { setting.IncomingEmail.Enabled = false }() @@ -77,7 +86,8 @@ func TestComposeIssueCommentMessage(t *testing.T) { msgs, err := composeIssueCommentMessages(&mailCommentContext{ Context: context.TODO(), // TODO: use a correct context Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue, - Content: "test body", Comment: comment, + Content: fmt.Sprintf("test @%s %s#%d body", doer.Name, issue.Repo.FullName(), issue.Index), + Comment: comment, }, "en-US", recipients, false, "issue comment") assert.NoError(t, err) assert.Len(t, msgs, 2) @@ -96,6 +106,20 @@ func TestComposeIssueCommentMessage(t *testing.T) { assert.Equal(t, "<user2/repo1/issues/1/comment/2@localhost>", gomailMsg.GetHeader("Message-ID")[0], "Message-ID header doesn't match") assert.Equal(t, "<mailto:"+replyTo+">", gomailMsg.GetHeader("List-Post")[0]) assert.Len(t, gomailMsg.GetHeader("List-Unsubscribe"), 2) // url + mailto + + var buf bytes.Buffer + gomailMsg.WriteTo(&buf) + + b, err := io.ReadAll(quotedprintable.NewReader(&buf)) + assert.NoError(t, err) + + // text/plain + assert.Contains(t, string(b), fmt.Sprintf(`( %s )`, doer.HTMLURL())) + assert.Contains(t, string(b), fmt.Sprintf(`( %s )`, issue.HTMLURL())) + + // text/html + assert.Contains(t, string(b), fmt.Sprintf(`href="%s"`, doer.HTMLURL())) + assert.Contains(t, string(b), fmt.Sprintf(`href="%s"`, issue.HTMLURL())) } func TestComposeIssueMessage(t *testing.T) { |