Skip to content

Commit ceaac61

Browse files
committed
templates: Be strict about undefined variables
We shouldn't have any reason to use undefined variables in MAS, so silently printing as empty strings (etc) seems undesirable. This will also be helpful for operators with custom templates, since then they will notice their templates being broken.
1 parent adad551 commit ceaac61

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/templates/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use camino::{Utf8Path, Utf8PathBuf};
1717
use mas_i18n::Translator;
1818
use mas_router::UrlBuilder;
1919
use mas_spa::ViteManifest;
20-
use minijinja::Value;
20+
use minijinja::{UndefinedBehavior, Value};
2121
use rand::Rng;
2222
use serde::Serialize;
2323
use thiserror::Error;
@@ -205,6 +205,8 @@ impl Templates {
205205
span.in_scope(move || {
206206
let mut loaded: HashSet<_> = HashSet::new();
207207
let mut env = minijinja::Environment::new();
208+
// Don't allow use of undefined variables
209+
env.set_undefined_behavior(UndefinedBehavior::Strict);
208210
let root = path.canonicalize_utf8()?;
209211
info!(%root, "Loading templates from filesystem");
210212
for entry in walkdir::WalkDir::new(&root)

0 commit comments

Comments
 (0)