mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-03 15:55:31 +00:00
Fix: canonicalize paths to ensure hashmap lookups behave as expected
This commit is contained in:
parent
f0ac41df30
commit
2cf65d18cc
@ -182,27 +182,40 @@ impl Config {
|
|||||||
start_at: Option<&Path>,
|
start_at: Option<&Path>,
|
||||||
file_info: Option<FileInfo<'_>>,
|
file_info: Option<FileInfo<'_>>,
|
||||||
) -> Result<Arc<Path>, CompileError> {
|
) -> Result<Arc<Path>, CompileError> {
|
||||||
|
fn _find_template(config: &Config, path: &str, start_at: Option<&Path>) -> Option<PathBuf> {
|
||||||
if let Some(root) = start_at {
|
if let Some(root) = start_at {
|
||||||
let relative = root.with_file_name(path);
|
let relative = root.with_file_name(path);
|
||||||
if relative.exists() {
|
if relative.exists() {
|
||||||
return Ok(relative.into());
|
return Some(relative);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for dir in &self.dirs {
|
for dir in &config.dirs {
|
||||||
let rooted = dir.join(path);
|
let rooted = dir.join(path);
|
||||||
if rooted.exists() {
|
if rooted.exists() {
|
||||||
return Ok(rooted.into());
|
return Some(rooted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(CompileError::new(
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(path) = _find_template(self, path, start_at) else {
|
||||||
|
return Err(CompileError::new(
|
||||||
format!(
|
format!(
|
||||||
"template {:?} not found in directories {:?}",
|
"template {:?} not found in directories {:?}",
|
||||||
path, self.dirs
|
path, self.dirs
|
||||||
),
|
),
|
||||||
file_info,
|
file_info,
|
||||||
))
|
));
|
||||||
|
};
|
||||||
|
match path.canonicalize() {
|
||||||
|
Ok(p) => Ok(p.into()),
|
||||||
|
Err(e) => Err(CompileError::no_file_info(
|
||||||
|
format_args!("could not canonicalize path {path:?}: {e}"),
|
||||||
|
None,
|
||||||
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user