From f4a7132a89f1e9ceb0e7d7e89a958db7a54c05cb Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 22 Oct 2024 15:15:09 +0200 Subject: [PATCH] fix: don't show truncated comments in RSS/Atom feeds - When a truncated comment is detected in the RSS/Atom feeds, fetch the comment from the database and use the original content. - Added integration test. - Resolves #5650 --- routers/web/feed/convert.go | 12 ++++++++++ tests/integration/api_feed_user_test.go | 23 +++++++++++++++++++ .../integration/fixtures/TestFeed/action.yml | 9 ++++++++ .../integration/fixtures/TestFeed/comment.yml | 8 +++++++ 4 files changed, 52 insertions(+) create mode 100644 tests/integration/fixtures/TestFeed/action.yml create mode 100644 tests/integration/fixtures/TestFeed/comment.yml diff --git a/routers/web/feed/convert.go b/routers/web/feed/convert.go index 0f4334692f..d3d01a87e0 100644 --- a/routers/web/feed/convert.go +++ b/routers/web/feed/convert.go @@ -13,7 +13,9 @@ import ( "strings" activities_model "code.gitea.io/gitea/models/activities" + issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" @@ -232,6 +234,16 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio case activities_model.ActionCommentIssue, activities_model.ActionApprovePullRequest, activities_model.ActionRejectPullRequest, activities_model.ActionCommentPull: desc = act.GetIssueTitle(ctx) comment := act.GetIssueInfos()[1] + if strings.HasSuffix(comment, "…") { + // Comment was truncated get the full content from the database. + // This truncation is done in `NotifyCreateIssueComment`. + commentModel, err := issues_model.GetCommentByID(ctx, act.CommentID) + if err != nil { + log.Error("Couldn't get comment[%d] for RSS feed: %v", act.CommentID, err) + } else { + comment = commentModel.Content + } + } if len(comment) != 0 { desc += "\n\n" + string(renderMarkdown(ctx, act, comment)) } diff --git a/tests/integration/api_feed_user_test.go b/tests/integration/api_feed_user_test.go index 7f3824963a..3fa9b86150 100644 --- a/tests/integration/api_feed_user_test.go +++ b/tests/integration/api_feed_user_test.go @@ -16,6 +16,7 @@ import ( ) func TestFeed(t *testing.T) { + defer tests.AddFixtures("tests/integration/fixtures/TestFeed/")() defer tests.PrepareTestEnv(t)() t.Run("User", func(t *testing.T) { @@ -42,6 +43,28 @@ func TestFeed(t *testing.T) { t.Run("Repo", func(t *testing.T) { t.Run("Normal", func(t *testing.T) { + t.Run("Atom", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1.atom") + resp := MakeRequest(t, req, http.StatusOK) + + data := resp.Body.String() + assert.Contains(t, data, `