pub fn sanitize_html(input: &str) -> StringExpand description
Sanitize HTML content, removing dangerous tags and attributes
This function uses ammonia to clean HTML content, allowing only safe tags and attributes. It’s designed to match feedparser’s sanitization behavior.
§Performance
This is a low-level primitive: it always runs the input through ammonia’s
HTML5 tree builder, which exhibits quadratic-time behavior on pathologically
deep tag nesting. Prefer sanitize_feed for parsed feed content — it
applies a nesting-depth bound (ParserLimits::max_html_nesting_depth) before
calling this function, falling back to plain-text escaping for input that
exceeds it.
§Arguments
input- HTML string to sanitize
§Returns
Sanitized HTML string with dangerous content removed
§Examples
use feedparser_rs::util::sanitize::sanitize_html;
let unsafe_html = r#"<p>Hello</p><script>alert('XSS')</script>"#;
let safe_html = sanitize_html(unsafe_html);
assert_eq!(safe_html, "<p>Hello</p>");