@@ -111,9 +111,11 @@ impl Tera {
111111
112112 /// Loads all the templates found in the glob that was given to Tera::new
113113 fn load_from_glob ( & mut self ) -> Result < ( ) > {
114- if self . glob . is_none ( ) {
115- return Err ( Error :: msg ( "Tera can only load from glob if a glob is provided" ) ) ;
116- }
114+ let glob = match & self . glob {
115+ Some ( g) => g,
116+ None => return Err ( Error :: msg ( "Tera can only load from glob if a glob is provided" ) ) ,
117+ } ;
118+
117119 // We want to preserve templates that have been added through
118120 // Tera::extend so we only keep those
119121 self . templates = self
@@ -125,14 +127,13 @@ impl Tera {
125127
126128 let mut errors = String :: new ( ) ;
127129
128- let dir = self . glob . clone ( ) . unwrap ( ) ;
129- // We clean the filename by removing the dir given
130- // to Tera so users don't have to prefix everytime
131- let mut parent_dir = dir. split_at ( dir. find ( '*' ) . unwrap ( ) ) . 0 ;
132- // Remove `./` from the glob if used as it would cause an error in strip_prefix
133- if parent_dir. starts_with ( "./" ) {
134- parent_dir = & parent_dir[ 2 ..] ;
135- }
130+ // Need to canonicalize the glob path because globwalk always returns
131+ // an empty list for paths starting with `./` or `../`.
132+ // See https://github.com/Keats/tera/issues/574 for the Tera discussion
133+ // and https://github.com/Gilnaa/globwalk/issues/28 for the upstream issue.
134+ let ( parent_dir, glob_end) = glob. split_at ( glob. find ( '*' ) . unwrap ( ) ) ;
135+ let parent_dir = std:: fs:: canonicalize ( parent_dir) . unwrap ( ) ;
136+ let dir = parent_dir. join ( glob_end) . into_os_string ( ) . into_string ( ) . unwrap ( ) ;
136137
137138 // We are parsing all the templates on instantiation
138139 for entry in glob_builder ( & dir)
0 commit comments