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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use ;
use crateTrustedHtml;
/// HTML cleaned by [ammonia](https://docs.rs/ammonia): a [`TrustedHtml`] for `v-html`, with the
/// `ammonia` feature.
///
/// The only ways to make one run the sanitiser: [`Sanitised::new`] with ammonia's default policy,
/// [`Sanitised::with`] with a policy of your own, and deserialising, which cleans the string with
/// the default policy. Name it as the `trustedHtml` type in `ferrovue.config.json`:
///
/// ```json
/// { "trustedHtml": "ferrovue::Sanitised" }
/// ```
///
/// It serialises as the cleaned string, so an island's `data-props` carries exactly the HTML the
/// server rendered, and the client's `v-html` writes the same string.
///
/// # Example
///
/// ```
/// use ferrovue::{Sanitised, trusted_into};
///
/// let body = Sanitised::new(r#"<p onclick="steal()">Hi <script>alert(1)</script><a href="javascript:x()">you</a></p>"#);
/// assert_eq!(body.as_str(), r#"<p>Hi <a rel="noopener noreferrer">you</a></p>"#);
///
/// let mut out = String::new();
/// trusted_into(&mut out, &body);
/// assert_eq!(out, body.as_str());
/// assert_eq!(serde_json::to_string(&body).unwrap(), r#""<p>Hi <a rel=\"noopener noreferrer\">you</a></p>""#);
///
/// let mut policy = ferrovue::ammonia::Builder::empty();
/// policy.add_tags(["em"]);
/// assert_eq!(Sanitised::with(&policy, "<p><em>only</em> this</p>").as_str(), "<em>only</em> this");
/// ```
;