From 5515d02df9e97d015137344673eda50e1c9c1c13 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 28 Sep 2023 15:15:45 +0200 Subject: [PATCH] Yield a parser error when defining a macro named 'super' --- askama_parser/src/node.rs | 9 +++++---- askama_parser/src/tests.rs | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs index 1ed4e40a1..a72c2fbef 100644 --- a/askama_parser/src/node.rs +++ b/askama_parser/src/node.rs @@ -474,16 +474,17 @@ impl<'a> Macro<'a> { ))); let (i, (contents, (_, pws2, _, nws2))) = end(i)?; - assert_ne!(name, "super", "invalid macro name 'super'"); - - let params = params.unwrap_or_default(); + if name == "super" { + // TODO: yield a a better error message here + return Err(nom::Err::Failure(Error::new(i, ErrorKind::Fail))); + } Ok(( i, Self { ws1: Ws(pws1, nws1), name, - args: params, + args: params.unwrap_or_default(), nodes: contents, ws2: Ws(pws2, nws2), }, diff --git a/askama_parser/src/tests.rs b/askama_parser/src/tests.rs index c23d13f69..3a7b4523c 100644 --- a/askama_parser/src/tests.rs +++ b/askama_parser/src/tests.rs @@ -795,3 +795,9 @@ fn fuzzed_unicode_slice() { 0!(!1q҄א!)!!!!!!n!"; assert!(Ast::from_str(d, &Syntax::default()).is_err()); } + +#[test] +fn fuzzed_macro_no_end() { + let s = "{%macro super%}{%endmacro"; + assert!(Ast::from_str(s, &Syntax::default()).is_err()); +}