mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Fix undetected cyclic dependency
This commit is contained in:
parent
66b53eecaf
commit
1899765230
@ -140,15 +140,12 @@ impl TemplateInput<'_> {
|
|||||||
Extends(extends) if top => {
|
Extends(extends) if top => {
|
||||||
let extends = self.config.find_template(extends.path, Some(&path))?;
|
let extends = self.config.find_template(extends.path, Some(&path))?;
|
||||||
let dependency_path = (path.clone(), extends.clone());
|
let dependency_path = (path.clone(), extends.clone());
|
||||||
if dependency_graph.contains(&dependency_path) {
|
if path == extends {
|
||||||
return Err(format!(
|
// We add the path into the graph to have a better looking error.
|
||||||
"cyclic dependency in graph {:#?}",
|
dependency_graph.push(dependency_path);
|
||||||
dependency_graph
|
return cyclic_graph_error(&dependency_graph);
|
||||||
.iter()
|
} else if dependency_graph.contains(&dependency_path) {
|
||||||
.map(|e| format!("{:#?} --> {:#?}", e.0, e.1))
|
return cyclic_graph_error(&dependency_graph);
|
||||||
.collect::<Vec<String>>()
|
|
||||||
)
|
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
dependency_graph.push(dependency_path);
|
dependency_graph.push(dependency_path);
|
||||||
add_to_check(extends)?;
|
add_to_check(extends)?;
|
||||||
@ -420,6 +417,17 @@ const TEXT_TYPES: [(Mime, Mime); 7] = [
|
|||||||
(mime::IMAGE_SVG, mime::IMAGE_SVG),
|
(mime::IMAGE_SVG, mime::IMAGE_SVG),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
fn cyclic_graph_error(dependency_graph: &[(Rc<Path>, Rc<Path>)]) -> Result<(), CompileError> {
|
||||||
|
Err(format!(
|
||||||
|
"cyclic dependency in graph {:#?}",
|
||||||
|
dependency_graph
|
||||||
|
.iter()
|
||||||
|
.map(|e| format!("{:#?} --> {:#?}", e.0, e.1))
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
)
|
||||||
|
.into())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user