123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- use dioxus::prelude::*;
- #[test]
- fn escape_static_values() {
- fn app() -> Element {
- rsx! { input { disabled: "\"><div>" } }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<input disabled=\""><div>\" data-node-hydration=\"0\"/>"
- );
- }
- #[test]
- fn escape_dynamic_values() {
- fn app() -> Element {
- let disabled = "\"><div>";
- rsx! { input { disabled } }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<input disabled=\""><div>\" data-node-hydration=\"0\"/>"
- );
- }
- #[test]
- fn escape_static_style() {
- fn app() -> Element {
- rsx! { div { width: "\"><div>" } }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<div style=\"width:"><div>;\" data-node-hydration=\"0\"></div>"
- );
- }
- #[test]
- fn escape_dynamic_style() {
- fn app() -> Element {
- let width = "\"><div>";
- rsx! { div { width } }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<div style=\"width:"><div>;\" data-node-hydration=\"0\"></div>"
- );
- }
- #[test]
- fn escape_static_text() {
- fn app() -> Element {
- rsx! {
- div {
- "\"><div>"
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<div data-node-hydration=\"0\">"><div></div>"
- );
- }
- #[test]
- fn escape_dynamic_text() {
- fn app() -> Element {
- let text = "\"><div>";
- rsx! {
- div {
- {text}
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<div data-node-hydration=\"0\"><!--node-id1-->"><div><!--#--></div>"
- );
- }
- #[test]
- fn don_t_escape_static_scripts() {
- fn app() -> Element {
- rsx! {
- script {
- "console.log('hello world');"
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<script data-node-hydration=\"0\">console.log('hello world');</script>"
- );
- }
- #[test]
- fn don_t_escape_dynamic_scripts() {
- fn app() -> Element {
- let script = "console.log('hello world');";
- rsx! {
- script {
- {script}
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<script data-node-hydration=\"0\"><!--node-id1-->console.log('hello world');<!--#--></script>"
- );
- }
- #[test]
- fn don_t_escape_static_styles() {
- fn app() -> Element {
- rsx! {
- style {
- "body {{ background-color: red; }}"
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<style data-node-hydration=\"0\">body { background-color: red; }</style>"
- );
- }
- #[test]
- fn don_t_escape_dynamic_styles() {
- fn app() -> Element {
- let style = "body { font-family: \"sans-serif\"; }";
- rsx! {
- style {
- {style}
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<style data-node-hydration=\"0\"><!--node-id1-->body { font-family: \"sans-serif\"; }<!--#--></style>"
- );
- }
- #[test]
- fn don_t_escape_static_fragment_styles() {
- fn app() -> Element {
- let style_element = rsx! { "body {{ font-family: \"sans-serif\"; }}" };
- rsx! {
- style {
- {style_element}
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<style data-node-hydration=\"0\"><!--node-id1-->body { font-family: \"sans-serif\"; }<!--#--></style>"
- );
- }
- #[test]
- fn escape_static_component_fragment_div() {
- #[component]
- fn StyleContents() -> Element {
- rsx! { "body {{ font-family: \"sans-serif\"; }}" }
- }
- fn app() -> Element {
- rsx! {
- div {
- StyleContents {}
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<div data-node-hydration=\"0\"><!--node-id1-->body { font-family: "sans-serif"; }<!--#--></div>"
- );
- }
- #[test]
- fn escape_dynamic_component_fragment_div() {
- #[component]
- fn StyleContents() -> Element {
- let dynamic = "body { font-family: \"sans-serif\"; }";
- rsx! { "{dynamic}" }
- }
- fn app() -> Element {
- rsx! {
- div {
- StyleContents {}
- }
- }
- }
- let mut dom = VirtualDom::new(app);
- dom.rebuild(&mut dioxus_core::NoOpMutations);
- assert_eq!(
- dioxus_ssr::pre_render(&dom),
- "<div data-node-hydration=\"0\"><!--node-id1-->body { font-family: "sans-serif"; }<!--#--></div>"
- );
- }
|