Skip to main content

embed_url

Function embed_url 

Source
pub fn embed_url(input: &str) -> Option<String>
Expand description

The canonical form of an address to embed, or None when it cannot be embedded.

Takes a plain URL or pasted embed code (<iframe ... src="...">), of which only src is kept. The address must be https with a plain host; the host is written in lower case, the port 443 is dropped, and tracking parameters (utm_* and TRACKING_PARAMS) are removed. Scripts, javascript: and data: addresses, user names and quotes give None.

assert_eq!(
    embed_url(r#"<iframe width="560" src="https://WWW.Example.com/embed/x?utm_source=a&amp;t=4" allowfullscreen></iframe>"#),
    Some("https://www.example.com/embed/x?t=4".to_string())
);
assert_eq!(embed_url("javascript:alert(1)"), None);