h-data: Remove rel attributes from <a> tags when sanitizing html.
They are invalid in `pango` markup so theres no reason they should are not needed. Also add some paranoid .trim() calls. It returnes a &str slice so it's cheap.
This commit is contained in:
parent
d332636dd4
commit
b74dbb74bb
@ -197,9 +197,9 @@ impl NewEpisodeMinimal {
|
|||||||
let guid = item.guid().map(|s| s.value().trim().to_owned());
|
let guid = item.guid().map(|s| s.value().trim().to_owned());
|
||||||
|
|
||||||
let uri = item.enclosure()
|
let uri = item.enclosure()
|
||||||
.map(|s| url_cleaner(s.url()))
|
.map(|s| url_cleaner(s.url().trim()))
|
||||||
// Fallback to Rss.Item.link if enclosure is None.
|
// Fallback to Rss.Item.link if enclosure is None.
|
||||||
.or_else(|| item.link().map(|s| url_cleaner(s)));
|
.or_else(|| item.link().map(|s| url_cleaner(s.trim())));
|
||||||
|
|
||||||
// If url is still None return an Error as this behaviour is
|
// If url is still None return an Error as this behaviour is
|
||||||
// compliant with the RSS Spec.
|
// compliant with the RSS Spec.
|
||||||
@ -234,7 +234,13 @@ impl NewEpisodeMinimal {
|
|||||||
// TODO: TryInto is stabilizing in rustc v1.26!
|
// TODO: TryInto is stabilizing in rustc v1.26!
|
||||||
pub(crate) fn into_new_episode(self, item: &rss::Item) -> NewEpisode {
|
pub(crate) fn into_new_episode(self, item: &rss::Item) -> NewEpisode {
|
||||||
let length = item.enclosure().and_then(|x| x.length().parse().ok());
|
let length = item.enclosure().and_then(|x| x.length().parse().ok());
|
||||||
let description = item.description().map(|s| ammonia::clean(s));
|
let description = item.description().map(|s| {
|
||||||
|
ammonia::Builder::new()
|
||||||
|
// Remove `rel` attributes from `<a>` tags
|
||||||
|
.link_rel(None)
|
||||||
|
.clean(chan.description().trim())
|
||||||
|
.to_string();
|
||||||
|
});
|
||||||
|
|
||||||
NewEpisodeBuilder::default()
|
NewEpisodeBuilder::default()
|
||||||
.title(self.title)
|
.title(self.title)
|
||||||
|
|||||||
@ -88,16 +88,20 @@ impl NewPodcast {
|
|||||||
/// Parses a `rss::Channel` into a `NewPodcast` Struct.
|
/// Parses a `rss::Channel` into a `NewPodcast` Struct.
|
||||||
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewPodcast {
|
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewPodcast {
|
||||||
let title = chan.title().trim();
|
let title = chan.title().trim();
|
||||||
|
let link = url_cleaner(chan.link().trim());
|
||||||
|
|
||||||
let description = ammonia::clean(chan.description().trim());
|
let description = ammonia::Builder::new()
|
||||||
let link = url_cleaner(chan.link());
|
// Remove `rel` attributes from `<a>` tags
|
||||||
|
.link_rel(None)
|
||||||
|
.clean(chan.description().trim())
|
||||||
|
.to_string();
|
||||||
|
|
||||||
// Try to get the itunes img first
|
// Try to get the itunes img first
|
||||||
let itunes_img = chan.itunes_ext()
|
let itunes_img = chan.itunes_ext()
|
||||||
.and_then(|s| s.image())
|
.and_then(|s| s.image().trim())
|
||||||
.map(|s| s.to_owned());
|
.map(|s| s.to_owned());
|
||||||
// If itunes is None, try to get the channel.image from the rss spec
|
// If itunes is None, try to get the channel.image from the rss spec
|
||||||
let image_uri = itunes_img.or_else(|| chan.image().map(|s| s.url().to_owned()));
|
let image_uri = itunes_img.or_else(|| chan.image().map(|s| s.url().trim().to_owned()));
|
||||||
|
|
||||||
NewPodcastBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title(title)
|
.title(title)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user