@@ -111,9 +111,10 @@ impl Tera {
111
111
112
112
/// Loads all the templates found in the glob that was given to Tera::new
113
113
fn load_from_glob ( & mut self ) -> Result < ( ) > {
114
- if self . glob . is_none ( ) {
114
+ let Some ( glob ) = & self . glob else {
115
115
return Err ( Error :: msg ( "Tera can only load from glob if a glob is provided" ) ) ;
116
- }
116
+ } ;
117
+
117
118
// We want to preserve templates that have been added through
118
119
// Tera::extend so we only keep those
119
120
self . templates = self
@@ -125,14 +126,13 @@ impl Tera {
125
126
126
127
let mut errors = String :: new ( ) ;
127
128
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
- }
129
+ // Need to canonicalize the glob path because globwalk always returns
130
+ // an empty list for paths starting with `./` or `../`.
131
+ // See https://github.com/Keats/tera/issues/574 for the Tera discussion
132
+ // and https://github.com/Gilnaa/globwalk/issues/28 for the upstream issue.
133
+ let ( parent_dir, glob_end) = glob. split_at ( glob. find ( '*' ) . unwrap ( ) ) ;
134
+ let parent_dir = std:: fs:: canonicalize ( parent_dir) . unwrap ( ) ;
135
+ let dir = parent_dir. join ( glob_end) . into_os_string ( ) . into_string ( ) . unwrap ( ) ;
136
136
137
137
// We are parsing all the templates on instantiation
138
138
for entry in glob_builder ( & dir)
0 commit comments