From a5033d9c699b715a9141d23d1661924b652f4750 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Mon, 2 Oct 2023 15:37:07 +0200 Subject: [PATCH] templates: expose escape_html function to fix tests --- Cargo.lock | 8 ++++++++ crates/templates/Cargo.toml | 3 ++- crates/templates/src/lib.rs | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 08dc7c04f..9f0205af4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3306,6 +3306,7 @@ dependencies = [ "tracing", "ulid", "url", + "v_htmlescape", "walkdir", ] @@ -3410,6 +3411,7 @@ dependencies = [ "self_cell", "serde", "serde_json", + "v_htmlescape", ] [[package]] @@ -6190,6 +6192,12 @@ dependencies = [ "serde", ] +[[package]] +name = "v_htmlescape" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e8257fbc510f0a46eb602c10215901938b5c2a7d5e70fc11483b1d3c9b5b18c" + [[package]] name = "valuable" version = "0.1.0" diff --git a/crates/templates/Cargo.toml b/crates/templates/Cargo.toml index 3964f2f2a..1813ed2fe 100644 --- a/crates/templates/Cargo.toml +++ b/crates/templates/Cargo.toml @@ -16,10 +16,11 @@ walkdir = "2.4.0" anyhow.workspace = true thiserror.workspace = true -minijinja = { workspace = true, features = ["loader", "json"] } +minijinja = { workspace = true, features = ["loader", "json", "speedups"] } serde.workspace = true serde_json.workspace = true serde_urlencoded = "0.7.1" +v_htmlescape = "0.15.8" camino.workspace = true chrono.workspace = true diff --git a/crates/templates/src/lib.rs b/crates/templates/src/lib.rs index d3741e17f..b3b9ca0cb 100644 --- a/crates/templates/src/lib.rs +++ b/crates/templates/src/lib.rs @@ -57,6 +57,14 @@ pub use self::{ forms::{FieldError, FormError, FormField, FormState, ToFormState}, }; +/// Escape the given string for use in HTML +/// +/// It uses the same crate as the one used by the minijinja templates +#[must_use] +pub fn escape_html(input: &str) -> String { + v_htmlescape::escape(input).to_string() +} + /// Wrapper around [`minijinja::Environment`] helping rendering the various /// templates #[derive(Debug, Clone)]