Skip to content

Commit

Permalink
Yield a parser error when defining a macro named 'super'
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Sep 28, 2023
1 parent c853049 commit 5515d02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions askama_parser/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down
6 changes: 6 additions & 0 deletions askama_parser/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 5515d02

Please sign in to comment.