Module sanitize_html::rules::pattern

source ·
Expand description

This module contains code dedicated to check validity of attribute’s value.

§Examples

use sanitize_html::rules::pattern::Pattern;
use regex::Regex;

let href = Pattern::regex(Regex::new("^(ftp:|http:|https:|mailto:)").unwrap()) |
    !Pattern::regex(Regex::new("^[^/]+[[:space:]]*:").unwrap());

assert!(href.matches("filename.xls"));
assert!(href.matches("http://foo.com/"));
assert!(href.matches(" filename with spaces .zip "));
assert!(!href.matches(" javascript  : window.location = '//example.com/'")); // Attempt to make XSS

Structs§