Skip to main content

sanitize_feed

Function sanitize_feed 

Source
pub fn sanitize_feed(feed: &mut ParsedFeed, limits: &ParserLimits)
Expand description

Sanitize every HTML-bearing field of a parsed feed, in place.

This is the single enforcement point for ParseOptions::sanitize_html. Format parsers populate ~85 fields across FeedMeta and Entry that can carry markup; sanitizing only at the handful of set_* convenience helpers would miss most of them (all of RSS 1.0, every entry.content push, dc:*/media:* fields). Walking the fully parsed structure once, after all format-specific parsing has finished, is the only way to cover every call site without duplicating sanitization logic into each parser.

Fields are matched against Python feedparser’s can_contain_dangerous_markup set: Tag.term/label, Person.name, Enclosure.title, comments, slash_hit_parade, Generator.name, and podcast free-text fields are deliberately excluded, since they are not rendered as markup by consumers.

§Examples

use feedparser_rs::{ParserLimits, parse, util::sanitize::sanitize_feed};

let xml = br#"<rss version="2.0"><channel><title>Feed</title>
    <item><title>Post</title>
    <description>&lt;script&gt;alert(1)&lt;/script&gt;Hi</description></item>
</channel></rss>"#;
let mut feed = parse(xml).unwrap();
sanitize_feed(&mut feed, &ParserLimits::default());
assert!(!feed.entries[0].summary.as_deref().unwrap_or("").contains("<script>"));