diff --git a/routers/web/feed/convert.go b/routers/web/feed/convert.go index 95b106225..31fbd1762 100644 --- a/routers/web/feed/convert.go +++ b/routers/web/feed/convert.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/util" "github.com/gorilla/feeds" + "github.com/jaytaylor/html2text" ) func toBranchLink(ctx *context.Context, act *activities_model.Action) string { @@ -240,8 +241,15 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio content = desc } + // It's a common practice for feed generators to use plain text titles. + // See https://codeberg.org/forgejo/forgejo/pulls/1595 + plainTitle, err := html2text.FromString(title, html2text.Options{OmitLinks: true}) + if err != nil { + return nil, err + } + items = append(items, &feeds.Item{ - Title: title, + Title: plainTitle, Link: link, Description: desc, Author: &feeds.Author{ diff --git a/tests/integration/api_feed_plain_text_titles_test.go b/tests/integration/api_feed_plain_text_titles_test.go new file mode 100644 index 000000000..a058b7321 --- /dev/null +++ b/tests/integration/api_feed_plain_text_titles_test.go @@ -0,0 +1,40 @@ +// Copyright 2023 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "net/http" + "testing" + + "code.gitea.io/gitea/tests" + + "github.com/stretchr/testify/assert" +) + +func TestFeedPlainTextTitles(t *testing.T) { + // This test verifies that items' titles in feeds are generated as plain text. + // See https://codeberg.org/forgejo/forgejo/pulls/1595 + + t.Run("Feed plain text titles", func(t *testing.T) { + t.Run("Atom", func(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + req := NewRequest(t, "GET", "/user2/repo1.atom") + resp := MakeRequest(t, req, http.StatusOK) + + data := resp.Body.String() + assert.Contains(t, data, "