aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-01-06 11:19:36 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-01-06 13:08:32 +0100
commit825ad5f816657bb6602467784491f3430320b4a5 (patch)
treedfd6464608646e85b06f749fd348229c77c1879f
parent7904325c1613fa307bb9a0fb5a1d5751420a063e (diff)
downloadaskama-825ad5f816657bb6602467784491f3430320b4a5.tar.gz
askama-825ad5f816657bb6602467784491f3430320b4a5.tar.bz2
askama-825ad5f816657bb6602467784491f3430320b4a5.zip
Add initial filter e for HTML escaping
-rw-r--r--Cargo.lock7
-rw-r--r--askama/Cargo.toml1
-rw-r--r--askama/src/filters.rs8
-rw-r--r--askama/src/lib.rs2
4 files changed, 18 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4c1a6a6..54facb2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -11,6 +11,7 @@ name = "askama"
version = "0.1.0"
dependencies = [
"askama_derive 0.1.0",
+ "htmlescape 0.3.1 (git+https://github.com/veddan/rust-htmlescape)",
]
[[package]]
@@ -23,6 +24,11 @@ dependencies = [
]
[[package]]
+name = "htmlescape"
+version = "0.3.1"
+source = "git+https://github.com/veddan/rust-htmlescape#1699b539179798e705ad8464128492a0a0092876"
+
+[[package]]
name = "nom"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -47,6 +53,7 @@ version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
+"checksum htmlescape 0.3.1 (git+https://github.com/veddan/rust-htmlescape)" = "<none>"
"checksum nom 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ffc564b2727f758993db55d4ffed0d84bbd7f387a66509516768c8f786bb0b10"
"checksum quote 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6732e32663c9c271bfc7c1823486b471f18c47a2dbf87c066897b7b51afc83be"
"checksum syn 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1a437f8b4353179418870f014113876cd4cd4f642e42dbc5ed4f328d5f808246"
diff --git a/askama/Cargo.toml b/askama/Cargo.toml
index b2e0fbe..7864818 100644
--- a/askama/Cargo.toml
+++ b/askama/Cargo.toml
@@ -6,3 +6,4 @@ workspace = ".."
[dependencies]
askama_derive = { path = "../askama_derive" }
+htmlescape = { git = "https://github.com/veddan/rust-htmlescape" }
diff --git a/askama/src/filters.rs b/askama/src/filters.rs
new file mode 100644
index 0000000..08feed3
--- /dev/null
+++ b/askama/src/filters.rs
@@ -0,0 +1,8 @@
+extern crate htmlescape;
+
+use std::fmt;
+
+pub fn e(s: &fmt::Display) -> String {
+ let s = format!("{}", s);
+ htmlescape::encode_minimal(&s)
+}
diff --git a/askama/src/lib.rs b/askama/src/lib.rs
index 2412b1f..f89683f 100644
--- a/askama/src/lib.rs
+++ b/askama/src/lib.rs
@@ -7,6 +7,8 @@ pub trait Template {
fn render(&self) -> String;
}
+pub mod filters;
+
#[cfg(test)]
mod tests {