feeds icon indicating copy to clipboard operation
feeds copied to clipboard

Spurious empty <summary> elements in atom feed

Open magical opened this issue 4 years ago • 12 comments

I have a feed in which items have a non-empty Content but an empty Description. This should result in an atom feed with a <content> element for the item but no <summary> element, but it seems that the feeds package always emits a <summary> element, even if it is empty.

https://play.golang.org/p/gE3aNOkeIqb

The feeds package should not should not emit a <summary> element if Item.Content is set but Item.Description is blank. Its presence may mislead feed readers into displaying the (empty) summary, ignoring the post content.

I'm currently working around the issue like this, but would prefer if this wasn't necessary.

atomFeed := (&feeds.Atom{feed}).AtomFeed()
for i := range atomFeed.Entries {
	atomFeed.Entries[i].Summary = nil
}

Versions

Go version: go version go1.14.3 linux/amd64 package version: 6f6e20dd3953594cd869cf981fb806440685cd21

Steps to Reproduce

How can the bug be triggered?

See code snippet below.

Output:
<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">
  <title>A blog</title>
  <id>http://example.net/</id>
  <updated>2009-11-10T23:00:00Z</updated>
  <link href="http://example.net/"></link>
  <author>
    <name>Test User</name>
    <email>[email protected]</email>
  </author>
  <entry>
    <title>Blog post</title>
    <updated>2009-11-10T23:00:00Z</updated>
    <id>tag:example.net,2009-11-10:/1</id>
    <content type="html">Full contents of the blog post</content>
    <link href="http://example.net/1" rel="alternate"></link>
    <summary type="html"></summary>
    <author>
      <name>Test User</name>
      <email>[email protected]</email>
    </author>
  </entry>
</feed>

Expected behavior

What output or behaviour were you expecting instead?

Expected output
<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">
  <title>A blog</title>
  <id>http://example.net/</id>
  <updated>2009-11-10T23:00:00Z</updated>
  <link href="http://example.net/"></link>
  <author>
    <name>Test User</name>
    <email>[email protected]</email>
  </author>
  <entry>
    <title>Blog post</title>
    <updated>2009-11-10T23:00:00Z</updated>
    <id>tag:example.net,2009-11-10:/1</id>
    <content type="html">Full contents of the blog post</content>
    <link href="http://example.net/1" rel="alternate"></link>
    <author>
      <name>Test User</name>
      <email>[email protected]</email>
    </author>
  </entry>
</feed>

Code Snippets

https://play.golang.org/p/gE3aNOkeIqb

package main

import (
	"log"
	"os"
	"time"

	"github.com/gorilla/feeds"
)

func main() {
	now := time.Now()
	feed := &feeds.Feed{
		Title:   "A blog",
		Link:    &feeds.Link{Href: "http://example.net/"},
		Author:  &feeds.Author{Name: "Test User", Email: "[email protected]"},
		Created: now,
	}

	feed.Items = []*feeds.Item{
		&feeds.Item{
			Title:   "Blog post",
			Link:    &feeds.Link{Href: "http://example.net/1"},
			Content: "Full contents of the blog post",
			Author:  &feeds.Author{Name: "Test User", Email: "[email protected]"},
			Created: now,
		},
	}

	err := feed.WriteAtom(os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}

magical avatar Aug 18 '20 00:08 magical

If you'd like to submit a PR with tests, I'd be happy to review and merge.

elithrar avatar Aug 18 '20 00:08 elithrar

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

stale[bot] avatar Oct 17 '20 20:10 stale[bot]

Ping @elithrar would you mind looking at the pull request?

magical avatar Oct 17 '20 20:10 magical

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

stale[bot] avatar Dec 19 '20 07:12 stale[bot]

still an issue

magical avatar Dec 19 '20 07:12 magical

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

stale[bot] avatar Jun 02 '21 17:06 stale[bot]

Poke

magical avatar Jun 02 '21 17:06 magical

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

stale[bot] avatar Aug 22 '21 18:08 stale[bot]

Bump. Happy anniversary.

magical avatar Aug 22 '21 20:08 magical

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

stale[bot] avatar Jan 09 '22 01:01 stale[bot]

poke

magical avatar Jan 15 '22 05:01 magical

Preemptively poking this before stalebot gets to it.

magical avatar Apr 16 '22 05:04 magical