pub struct BubbleBath<'a> {
pub allowed_generic_attributes: HashSet<&'a str>,
pub allowed_tags: HashSet<&'a str>,
pub allowed_tag_attributes: HashMap<&'a str, HashSet<&'a str>>,
pub allowed_url_schemes: HashSet<&'a str>,
pub clean_url_attributes: HashMap<&'a str, HashSet<&'a str>>,
pub memory_settings: MemorySettings,
pub preserve_escaped: bool,
pub remove_content_tags: HashSet<&'a str>,
pub set_tag_attributes: HashMap<&'a str, HashMap<&'a str, &'a str>>,
}Expand description
HTML sanitizer
bubble-bath is allow-list based, meaning all tags are by default cleaned.
BubbleBath::default provides a safe default
§Implementation details
- We use
lol_htmlas our underlying HTML processor - Only absolute URLs (i.e. URLs with a scheme) are allowed. Relative links are discarded
Fields§
§allowed_generic_attributes: HashSet<&'a str>Attributes you want to keep on all tags
Tags you want to keep
allowed_tag_attributes: HashMap<&'a str, HashSet<&'a str>>Attributes you want to keep on a per-tag basis
allowed_url_schemes: HashSet<&'a str>Schemes you want to allow on URLs in anchor tags
clean_url_attributes: HashMap<&'a str, HashSet<&'a str>>Clean certain attributes on tags as if they are URLs
memory_settings: MemorySettingsMemory settings for the underlying HTML transformer
preserve_escaped: boolInstead of removing tags (and potentially their content), escape the HTML instead and output them as raw text
Tags of which you want to remove the tag and the content of
By default bubble-bath preserves the content of tags
Note: Remember to put <script> and <style> tags in here (unless you 100% know what you are doing) since they are really damn evil!
set_tag_attributes: HashMap<&'a str, HashMap<&'a str, &'a str>>Attributes you want to set on a per-tag basis
Implementations§
Source§impl BubbleBath<'_>
impl BubbleBath<'_>
Sourcepub fn clean_streaming<'a, I, S>(&self, input: I, sink: S) -> Result<(), Error>
pub fn clean_streaming<'a, I, S>(&self, input: I, sink: S) -> Result<(), Error>
Clean HTML in a streaming fashion
§Errors
- The HTML rewriter ran out of memory
- The HTML parser ran into an ambiguous state (in this case you should just discard the text instead of trying to fix it)
- The name of an attribute you put into the
set_tag_attributeshashmap is invalid