aboutsummaryrefslogtreecommitdiffstats
path: root/tests/misc_dangerous_html.rs
blob: 0610d23170fda9c66fa1870803128d1cf892fb5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
extern crate markdown;
use markdown::{to_html, to_html_with_options, CompileOptions, Options};
use pretty_assertions::assert_eq;

#[test]
fn dangerous_html() -> Result<(), String> {
    let danger = &Options {
        compile: CompileOptions {
            allow_dangerous_html: true,
            allow_dangerous_protocol: true,
            ..Default::default()
        },
        ..Default::default()
    };

    assert_eq!(
        to_html("<x>"),
        "&lt;x&gt;",
        "should be safe by default for flow"
    );

    assert_eq!(
        to_html("a<b>"),
        "<p>a&lt;b&gt;</p>",
        "should be safe by default for text"
    );

    assert_eq!(
        to_html_with_options("<x>", danger)?,
        "<x>",
        "should be unsafe w/ `allowDangerousHtml`"
    );

    Ok(())
}