diff --git a/src/tera.rs b/src/tera.rs index bf29f6d8..81f9057b 100644 --- a/src/tera.rs +++ b/src/tera.rs @@ -132,7 +132,13 @@ impl Tera { // See https://github.com/Keats/tera/issues/574 for the Tera discussion // and https://github.com/Gilnaa/globwalk/issues/28 for the upstream issue. let (parent_dir, glob_end) = glob.split_at(glob.find('*').unwrap()); - let parent_dir = std::fs::canonicalize(parent_dir)?; + let parent_dir = match std::fs::canonicalize(parent_dir) { + Ok(d) => d, + // If canonicalize fails, just abort it and resume with the given path. + // Consumers expect invalid globs to just return the empty set instead of failing. + // See https://github.com/Keats/tera/issues/819#issuecomment-1480392230 + Err(_) => std::path::PathBuf::from(parent_dir), + }; let dir = parent_dir.join(glob_end).into_os_string().into_string().unwrap(); // We are parsing all the templates on instantiation @@ -1222,9 +1228,10 @@ mod tests { // https://github.com/Keats/tera/issues/819 #[test] - fn doesnt_panic_on_invalid_glob() { + fn empty_list_on_invalid_glob() { let tera = Tera::new("\\dev/null/*"); println!("{:?}", tera); - assert!(tera.is_err()); + assert!(tera.is_ok()); + assert!(tera.unwrap().templates.is_empty()); } }