Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error out if glob passed to Tera::new starts with ./ #797

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/tera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ impl Tera {
if self.glob.is_none() {
return Err(Error::msg("Tera can only load from glob if a glob is provided"));
}

let dir = self.glob.clone().unwrap();

if dir.starts_with("./") || dir.starts_with("../") {
// Because globwalk has issues with globs starting with ./ or ../
// jee https://github.com/Keats/tera/issues/574
return Err(Error::msg("Globs starting with './' or '../' are not supported, please canonicalize the path."));
}

// We want to preserve templates that have been added through
// Tera::extend so we only keep those
self.templates = self
Expand All @@ -125,14 +134,9 @@ 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..];
}
let parent_dir = dir.split_at(dir.find('*').unwrap()).0;

// We are parsing all the templates on instantiation
for entry in glob_builder(&dir)
Expand Down