Skip to content

Commit

Permalink
Fix iTunes extension writing
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed May 29, 2023
1 parent 9cc3619 commit a921f66
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 2.x.x - Unreleased

- Fix iTunes extension writing [`#151`](https://github.com/rust-syndication/rss/pull/151)

## 2.0.3 - 2023-03-27

- Upgrade `quick_xml` to `0.28` [`#146`](https://github.com/rust-syndication/rss/pull/146)
Expand Down
8 changes: 7 additions & 1 deletion src/extension/itunes/itunes_channel_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use quick_xml::events::{BytesStart, Event};
use quick_xml::Error as XmlError;
use quick_xml::Writer;

use super::{parse_categories, parse_image, parse_owner};
use super::{parse_categories, parse_image, parse_owner, NAMESPACE};
use crate::extension::itunes::{ITunesCategory, ITunesOwner};
use crate::extension::util::remove_extension_value;
use crate::extension::Extension;
Expand Down Expand Up @@ -553,6 +553,12 @@ impl ToXml for ITunesChannelExtension {

Ok(())
}

fn used_namespaces(&self) -> BTreeMap<String, String> {
let mut namespaces = BTreeMap::new();
namespaces.insert("itunes".to_owned(), NAMESPACE.to_owned());
namespaces
}
}

#[cfg(feature = "builders")]
Expand Down
32 changes: 30 additions & 2 deletions tests/write.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extern crate rss;

use rss::{
extension, CategoryBuilder, Channel, ChannelBuilder, CloudBuilder, EnclosureBuilder,
GuidBuilder, ImageBuilder, Item, ItemBuilder, SourceBuilder, TextInputBuilder,
extension, extension::itunes::ITunesChannelExtensionBuilder, CategoryBuilder, Channel,
ChannelBuilder, CloudBuilder, EnclosureBuilder, GuidBuilder, ImageBuilder, Item, ItemBuilder,
SourceBuilder, TextInputBuilder,
};
use std::collections::BTreeMap;

Expand Down Expand Up @@ -105,6 +106,33 @@ fn write_itunes() {
test_write!(channel);
}

#[test]
fn write_itunes_namespace() {
let itunes_extention = ITunesChannelExtensionBuilder::default()
.author(Some("author".to_string()))
.build();
let channel = rss::ChannelBuilder::default()
.title("Channel Title")
.link("http://example.com")
.description("Channel Description")
.itunes_ext(itunes_extention)
.build();

let xml = String::from_utf8(channel.pretty_write_to(Vec::new(), b' ', 4).unwrap()).unwrap();
assert_eq!(
xml,
r##"<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>Channel Title</title>
<link>http://example.com</link>
<description>Channel Description</description>
<itunes:author>author</itunes:author>
</channel>
</rss>"##
);
}

#[test]
fn write_dublincore() {
let input = include_str!("data/dublincore.xml");
Expand Down

0 comments on commit a921f66

Please sign in to comment.