Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore case when looking for iTunes extension namespace #159

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.x.x - Unreleased

- Update `chrono` to 0.4.31 [`#160`](https://github.com/rust-syndication/rss/pull/160)
- Change how iTunes extension is detected. Use case insensitive comparison of a namespace [`#159`](https://github.com/rust-syndication/rss/pull/159)

## 2.0.6 - 2023-08-12

Expand Down
9 changes: 6 additions & 3 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::error::Error;
#[cfg(feature = "atom")]
use crate::extension::atom;
use crate::extension::dublincore;
use crate::extension::itunes;
use crate::extension::itunes::{self, is_itunes_namespace};
use crate::extension::syndication;
use crate::extension::util::{
extension_entry, extension_name, parse_extension_element, read_namespace_declarations,
Expand Down Expand Up @@ -1299,8 +1299,11 @@ impl Channel {
Some(ns @ atom::NAMESPACE) => {
extension_entry(&mut extensions, ns, name).push(ext);
}
Some(ns @ itunes::NAMESPACE)
| Some(ns @ dublincore::NAMESPACE)
Some(ns) if is_itunes_namespace(ns) => {
extension_entry(&mut extensions, itunes::NAMESPACE, name)
.push(ext);
}
Some(ns @ dublincore::NAMESPACE)
| Some(ns @ syndication::NAMESPACE) => {
extension_entry(&mut extensions, ns, name).push(ext);
}
Expand Down
8 changes: 8 additions & 0 deletions src/extension/itunes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ pub use self::itunes_owner::*;
/// The iTunes XML namespace.
pub const NAMESPACE: &str = "http://www.itunes.com/dtds/podcast-1.0.dtd";

/// Formally XML namespace is case sensitive and this should be just an equality check.
/// But many podcast publishers ignore this and use different case variations of the namespace.
/// Hence this check is relaxed and ignores a case.
#[inline]
pub(crate) fn is_itunes_namespace(ns: &str) -> bool {
ns.eq_ignore_ascii_case(NAMESPACE)
}

fn parse_image(map: &mut BTreeMap<String, Vec<Extension>>) -> Option<String> {
let mut element = match map.remove("image").map(|mut v| v.remove(0)) {
Some(element) => element,
Expand Down
8 changes: 6 additions & 2 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::error::Error;
#[cfg(feature = "atom")]
use crate::extension::atom;
use crate::extension::dublincore;
use crate::extension::itunes;
use crate::extension::itunes::{self, is_itunes_namespace};
use crate::extension::util::{
extension_entry, extension_name, parse_extension_element, read_namespace_declarations,
};
Expand Down Expand Up @@ -660,7 +660,11 @@ impl Item {
Some(ns @ atom::NAMESPACE) => {
extension_entry(&mut extensions, ns, name).push(ext);
}
Some(ns @ itunes::NAMESPACE) | Some(ns @ dublincore::NAMESPACE) => {
Some(ns) if is_itunes_namespace(ns) => {
extension_entry(&mut extensions, itunes::NAMESPACE, name)
.push(ext);
}
Some(ns @ dublincore::NAMESPACE) => {
extension_entry(&mut extensions, ns, name).push(ext);
}
_ => extension_entry(&mut item.extensions, prefix, name).push(ext),
Expand Down