use ruma_html::{Html, SanitizerConfig}; #[test] fn valid_input() { let config = SanitizerConfig::strict().remove_reply_fallback(); let mut html = Html::parse( "\
This is a paragraph with some color
\<mx-reply>This is a fake reply</mx-reply>
\
",
);
html.sanitize_with(config);
assert_eq!(
html.to_string(),
"\
This is a paragraph with some color
\<mx-reply>This is a fake reply</mx-reply>
\
"
);
}
#[test]
fn tags_remove() {
let config = SanitizerConfig::strict();
let mut html = Html::parse(
"\
\ In reply to \ @alice:example.com\\
\ Previous message\
But this is inside a tag
\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\\ In reply to \ @alice:example.com\\
\ Previous message\
But this is inside a tag
\ " ); } #[test] fn tags_remove_without_reply() { let config = SanitizerConfig::strict().remove_reply_fallback(); let mut html = Html::parse( "\\ In reply to \ @alice:example.com\\
\ Previous message\
But this is inside a tag
\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\ This has no tag\But this is inside a tag
\ " ); } #[test] fn tags_remove_only_reply_fallback() { let config = SanitizerConfig::new().remove_reply_fallback(); let mut html = Html::parse( "\\ In reply to \ @alice:example.com\\
\ Previous message\
But this is inside a tag
\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\But this is inside a tag
\ " ); } #[test] fn attrs_remove() { let config = SanitizerConfig::strict(); let mut html = Html::parse( "\Look at me!
\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\Look at me!
\ " ); } #[test] fn img_remove_scheme() { let config = SanitizerConfig::strict(); let mut html = Html::parse( "\Look at that picture:
\Look at that picture:
"); } #[test] fn link_remove_scheme() { let config = SanitizerConfig::strict(); let mut html = Html::parse( "\Go see my local website
\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\Go see my local website
\ " ); } #[test] fn link_compat_scheme() { let config = SanitizerConfig::strict(); let mut html = Html::parse( "\Join my room
\To talk about my cat
\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\Join my room
\To talk about my cat
\ " ); let config = SanitizerConfig::compat(); let mut html = Html::parse( "\Join my room
\To talk about my cat
\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\Join my room
\To talk about my cat
\ " ); } #[test] fn class_remove() { let config = SanitizerConfig::strict(); let mut html = Html::parse( "\
type StringList = Vec<String>;
\
What do you think of the name StringList
?
type StringList = Vec<String>;
\
What do you think of the name StringList
?
Look at you me!
Look at you me!