rust-syndication / rss

Library for serializing the RSS web content syndication format
https://crates.io/crates/rss
Apache License 2.0
419 stars 52 forks source link

Invalid RSS feed when having 0 items in a podcast #150

Closed SamTV12345 closed 1 year ago

SamTV12345 commented 1 year ago

I get an invalid RSS feed when I try to create an RSS feed that has the itunes author set but has no items. This is because in the rss tag no itunes extension is defined. It seems that adding that namespace is solely dependent from the added items.

If no items exist it still adds itunes author etc. but fails to add the namespace.

Reproduction

  1. docker run -p 80:8000 samuel19982/podfetch:latest
  2. Go to info -> click on the RSS feed link
  3. An error is shown in Chrome/Firefox because of the missing namespace.
andy128k commented 1 year ago

You need to call .itunes_ext(itunes_ext) here

SamTV12345 commented 1 year ago

This is a bug report not a asking for help. Take this example:

fn main() {
    let itunes_extention = ITunesChannelExtensionBuilder::default().author(Some("author".to_string()))
        .build();
    // create a rss channel
    let channel = rss::ChannelBuilder::default()
        .title("Channel Title")
        .link("http://example.com")
        .description("Channel Description")
        .itunes_ext(itunes_extention)
        .build();
    println!("{}",channel.to_string())
}

Which generates this:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Channel Title</title>
<link>http://example.com</link>
<description>Channel Description</description>
<itunes:author>author</itunes:author></channel>
</rss>

This errors in every browser because the itunes namespace is missing. This is equivalent to having an empty items vector.

This is tested on 2.0.2 and 2.0.3 which is the latest version.

andy128k commented 1 year ago

@SamTV12345 Thanks for reporting. That's actually a nasty bug.

SamTV12345 commented 1 year ago

Sure no problem. A user of my app discovered that as he set the downloaded podcasts to 0 (I only display downloaded podcasts in the RSS feed). Now I'm always checking if the items is 0 then I don't include the itunes author etc.

andy128k commented 1 year ago

A fix is released in 2.0.4

SamTV12345 commented 1 year ago

Thanks for the quick fix.