diff options
author | Gaurav Tyagi <grvtyagi22@gmail.com> | 2021-10-25 16:02:52 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-25 12:32:52 +0200 |
commit | 028eb1c3103ee59163b7b14829583a174a43b12a (patch) | |
tree | aa53a4578f5c98872ddda0450a65b5c9efd0f1ec /askama_derive | |
parent | c26d511fc008da2279c242dde4d69c50753332c4 (diff) | |
download | askama-028eb1c3103ee59163b7b14829583a174a43b12a.tar.gz askama-028eb1c3103ee59163b7b14829583a174a43b12a.tar.bz2 askama-028eb1c3103ee59163b7b14829583a174a43b12a.zip |
Handle build hangs due to unintended template recursion. (#539)
Diffstat (limited to 'askama_derive')
-rw-r--r-- | askama_derive/src/lib.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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<PathBuf, String>, 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::<Vec<String>>() + ))); + } + dependency_graph.push(dependency_path); let source = get_template_source(&extends)?; check.push((extends, source)); } |