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\
\
\ This has no tag\

But this is inside a tag

\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\ \
\ In reply to \ @alice:example.com\
\ Previous message\
\
\ This has no tag\

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\
\
\ This has no tag\

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\
\
\ This keeps its tag\

But this is inside a tag

\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\ This keeps its tag\

But this is inside a tag

\ " ); } #[test] fn attrs_remove() { let config = SanitizerConfig::strict(); let mut html = Html::parse( "\

Title for important stuff

\

Look at me!

\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\

Title for important stuff

\

Look at me!

\ " ); } #[test] fn img_remove_scheme() { let config = SanitizerConfig::strict(); let mut html = Html::parse( "\

Look at that picture:

\ \ ", ); html.sanitize_with(config); assert_eq!(html.to_string(), "

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?

\ ", ); html.sanitize_with(config); assert_eq!( html.to_string(), "\

            type StringList = Vec<String>;
        
\

What do you think of the name StringList?

\ " ); } #[test] fn depth_remove() { let config = SanitizerConfig::strict(); let deeply_nested_html: String = std::iter::repeat("
") .take(100) .chain(Some( "I am in too deep!\ I should be fine.", )) .chain(std::iter::repeat("
").take(100)) .collect(); let mut html = Html::parse(&deeply_nested_html); html.sanitize_with(config); let res = html.to_string(); assert!(res.contains("I should be fine.")); assert!(!res.contains("I am in too deep!")); }