escape text in ssr

This commit is contained in:
Evan Almloff committed 2023-02-14 08:44:01 -06:00
1 parent bea16f151f
commit c9f9b8b0fa
3 files changed
+13 -3

No files matched your search

+1
View File
@@ -14,6 +14,7 @@ keywords = ["dom", "ui", "gui", "react", "ssr"]
[dependencies]
dioxus-core = { path = "../core", version = "^0.3.0", features = ["serialize"] }
askama_escape = "0.10.3"
[dev-dependencies]
dioxus = { path = "../dioxus", version = "0.3.0" }
+7 -1
View File
@@ -82,7 +82,13 @@ impl StringCache {
}
cur_path.pop();
}
TemplateNode::Text { text } => write!(chain, "{text}")?,
TemplateNode::Text { text } => {
write!(
chain,
"{}",
askama_escape::escape(text, askama_escape::Html)
)?;
}
TemplateNode::Dynamic { id: idx } | TemplateNode::DynamicText { id: idx } => {
chain.segments.push(Segment::Node(*idx))
}
+5 -2
View File
@@ -104,8 +104,11 @@ impl Renderer {
write!(buf, "<!--#-->")?;
}
// todo: escape the text
write!(buf, "{}", text.value)?;
write!(
buf,
"{}",
askama_escape::escape(text.value, askama_escape::Html)
)?;
if self.pre_render {
write!(buf, "<!--#-->")?;