diff --git a/src/tera.rs b/src/tera.rs index 2f6de338..a68b277d 100644 --- a/src/tera.rs +++ b/src/tera.rs @@ -111,9 +111,11 @@ impl Tera { /// Loads all the templates found in the glob that was given to Tera::new fn load_from_glob(&mut self) -> Result<()> { - if self.glob.is_none() { - return Err(Error::msg("Tera can only load from glob if a glob is provided")); - } + let glob = match &self.glob { + Some(g) => g, + None => return Err(Error::msg("Tera can only load from glob if a glob is provided")), + }; + // We want to preserve templates that have been added through // Tera::extend so we only keep those self.templates = self @@ -125,14 +127,13 @@ impl Tera { let mut errors = String::new(); - let dir = self.glob.clone().unwrap(); - // We clean the filename by removing the dir given - // to Tera so users don't have to prefix everytime - let mut parent_dir = dir.split_at(dir.find('*').unwrap()).0; - // Remove `./` from the glob if used as it would cause an error in strip_prefix - if parent_dir.starts_with("./") { - parent_dir = &parent_dir[2..]; - } + // Need to canonicalize the glob path because globwalk always returns + // an empty list for paths starting with `./` or `../`. + // 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).unwrap(); + let dir = parent_dir.join(glob_end).into_os_string().into_string().unwrap(); // We are parsing all the templates on instantiation for entry in glob_builder(&dir)