From 825ad5f816657bb6602467784491f3430320b4a5 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 6 Jan 2017 11:19:36 +0100 Subject: Add initial filter e for HTML escaping --- Cargo.lock | 7 +++++++ askama/Cargo.toml | 1 + askama/src/filters.rs | 8 ++++++++ askama/src/lib.rs | 2 ++ 4 files changed, 18 insertions(+) create mode 100644 askama/src/filters.rs 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]] @@ -22,6 +23,11 @@ dependencies = [ "syn 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "htmlescape" +version = "0.3.1" +source = "git+https://github.com/veddan/rust-htmlescape#1699b539179798e705ad8464128492a0a0092876" + [[package]] name = "nom" version = "2.0.1" @@ -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)" = "" "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 { -- cgit