@@ -71,6 +71,9 @@ pub struct Templates {
7171 vite_manifest_path : Utf8PathBuf ,
7272 translations_path : Utf8PathBuf ,
7373 path : Utf8PathBuf ,
74+ /// Whether template rendering is in strict mode (for testing,
75+ /// until this can be rolled out in production.)
76+ strict : bool ,
7477}
7578
7679/// There was an issue while loading the templates
@@ -151,6 +154,7 @@ impl Templates {
151154 translations_path : Utf8PathBuf ,
152155 branding : SiteBranding ,
153156 features : SiteFeatures ,
157+ strict : bool ,
154158 ) -> Result < Self , TemplateLoadingError > {
155159 let ( translator, environment) = Self :: load_ (
156160 & path,
@@ -159,6 +163,7 @@ impl Templates {
159163 & translations_path,
160164 branding. clone ( ) ,
161165 features,
166+ strict,
162167 )
163168 . await ?;
164169 Ok ( Self {
@@ -170,6 +175,7 @@ impl Templates {
170175 translations_path,
171176 branding,
172177 features,
178+ strict,
173179 } )
174180 }
175181
@@ -180,6 +186,7 @@ impl Templates {
180186 translations_path : & Utf8Path ,
181187 branding : SiteBranding ,
182188 features : SiteFeatures ,
189+ strict : bool ,
183190 ) -> Result < ( Arc < Translator > , Arc < minijinja:: Environment < ' static > > ) , TemplateLoadingError > {
184191 let path = path. to_owned ( ) ;
185192 let span = tracing:: Span :: current ( ) ;
@@ -206,7 +213,14 @@ impl Templates {
206213 let mut loaded: HashSet < _ > = HashSet :: new ( ) ;
207214 let mut env = minijinja:: Environment :: new ( ) ;
208215 // Don't allow use of undefined variables
209- env. set_undefined_behavior ( UndefinedBehavior :: Strict ) ;
216+ env. set_undefined_behavior ( if strict {
217+ UndefinedBehavior :: Strict
218+ } else {
219+ // For now, allow semi-strict, because we don't have total test coverage of
220+ // tests and some tests rely on if conditions against sometimes-undefined
221+ // variables
222+ UndefinedBehavior :: SemiStrict
223+ } ) ;
210224 let root = path. canonicalize_utf8 ( ) ?;
211225 info ! ( %root, "Loading templates from filesystem" ) ;
212226 for entry in walkdir:: WalkDir :: new ( & root)
@@ -277,6 +291,7 @@ impl Templates {
277291 & self . translations_path ,
278292 self . branding . clone ( ) ,
279293 self . features ,
294+ self . strict ,
280295 )
281296 . await ?;
282297
@@ -526,6 +541,8 @@ mod tests {
526541 translations_path,
527542 branding,
528543 features,
544+ // Use strict mode in tests
545+ true ,
529546 )
530547 . await
531548 . unwrap ( ) ;
0 commit comments