From 028eb1c3103ee59163b7b14829583a174a43b12a Mon Sep 17 00:00:00 2001 From: Gaurav Tyagi Date: Mon, 25 Oct 2021 16:02:52 +0530 Subject: Handle build hangs due to unintended template recursion. (#539) --- askama_derive/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'askama_derive') diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index f97fa90..f2bee66 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -75,12 +75,24 @@ fn find_used_templates( map: &mut HashMap, source: String, ) -> Result<(), CompileError> { + let mut dependency_graph = Vec::new(); let mut check = vec![(input.path.clone(), source)]; while let Some((path, source)) = check.pop() { for n in parse(&source, input.syntax)? { match n { Node::Extends(Expr::StrLit(extends)) => { let extends = input.config.find_template(extends, Some(&path))?; + let dependency_path = (path.clone(), extends.clone()); + if dependency_graph.contains(&dependency_path) { + return Err(CompileError::String(format!( + "cyclic dependecy in graph {:#?}", + dependency_graph + .iter() + .map(|e| format!("{:#?} --> {:#?}", e.0, e.1)) + .collect::>() + ))); + } + dependency_graph.push(dependency_path); let source = get_template_source(&extends)?; check.push((extends, source)); } -- cgit