aboutsummaryrefslogtreecommitdiffstats
path: root/askama_parser/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar René Kijewski <rene.kijewski@fu-berlin.de>2023-09-28 17:09:29 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-09-28 17:28:26 +0200
commit238e4bbad7712ccc3a3ea4a5b09c63bd147c692e (patch)
tree6cf335c2365a99115d931e4657576d902526bdb1 /askama_parser/src/lib.rs
parent36f4442978674a79aaebefcd4f04c7bfe6fe54c4 (diff)
downloadaskama-238e4bbad7712ccc3a3ea4a5b09c63bd147c692e.tar.gz
askama-238e4bbad7712ccc3a3ea4a5b09c63bd147c692e.tar.bz2
askama-238e4bbad7712ccc3a3ea4a5b09c63bd147c692e.zip
Limit nesting in parser nodes, too
Diffstat (limited to 'askama_parser/src/lib.rs')
-rw-r--r--askama_parser/src/lib.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/askama_parser/src/lib.rs b/askama_parser/src/lib.rs
index de88a20..3428735 100644
--- a/askama_parser/src/lib.rs
+++ b/askama_parser/src/lib.rs
@@ -255,6 +255,7 @@ fn path_or_identifier(i: &str) -> IResult<&str, PathOrIdentifier<'_>> {
struct State<'a> {
syntax: &'a Syntax<'a>,
loop_depth: Cell<usize>,
+ level: Cell<Level>,
}
impl<'a> State<'a> {
@@ -262,9 +263,19 @@ impl<'a> State<'a> {
State {
syntax,
loop_depth: Cell::new(0),
+ level: Cell::new(Level::default()),
}
}
+ fn nest<'b>(&self, i: &'b str) -> Result<(), nom::Err<nom::error::Error<&'b str>>> {
+ self.level.set(self.level.get().nest(i)?);
+ Ok(())
+ }
+
+ fn leave(&self) {
+ self.level.set(self.level.get().leave());
+ }
+
fn tag_block_start<'i>(&self, i: &'i str) -> IResult<&'i str, &'i str> {
tag(self.syntax.block_start)(i)
}
@@ -337,5 +348,9 @@ impl Level {
Ok(Level(self.0 + 1))
}
+ fn leave(&self) -> Self {
+ Level(self.0 - 1)
+ }
+
const MAX_DEPTH: u8 = 64;
}