//! Simple, safe server-side html templating in Rust //! //! Build up a representation of an html page using plain Rust functions. Call `to_string()` on the //! result to spit out an html string //! //! //! The approach to XSS prevention is based on [this //! guide](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#introduction). //! //! Here are a few things to keep in mind: //! - All attribute keys need to be known at compile time. This avoids having them created //! dynamically (and having to escape them). //! - The values for `href`, `src` and `action` attributes are automatically url-encoded. //! - All attribute values are double quoted. This makes escaping in attribute contexts easier //! - All text is html escaped, except for css within [unsafe_style](crate::tags::unsafe_style). //! - The `style` attribute is not supported. Use the [unsafe_style](crate::tags::unsafe_style) tag instead. //! - Content _within_ `"# ); } #[test] fn event_handler_attributes_not_supported() { let node = div(attr! { "onclick" => "alert(1);" }); assert_eq!(node.to_string(), r#"
"#); } #[test] fn encode_html() { let node = div(r#""'&boo'"#); assert_eq!( node.to_string(), r#"