Skip to content

Commit

Permalink
Ignore case when looking for iTunes extension namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Jan 13, 2024
1 parent 2accbd7 commit 1ea0254
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
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

0 comments on commit 1ea0254

Please sign in to comment.