From 2e8e42af457732f25d00b2c5d42695353d301804 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 11 Sep 2023 11:41:24 +0200 Subject: Use char_indices() to get byte indices for characters --- askama_parser/src/expr.rs | 2 +- askama_parser/src/tests.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/askama_parser/src/expr.rs b/askama_parser/src/expr.rs index 3e63d93..7f82266 100644 --- a/askama_parser/src/expr.rs +++ b/askama_parser/src/expr.rs @@ -254,7 +254,7 @@ impl<'a> Suffix<'a> { let mut in_str = false; let mut escaped = false; - for (i, c) in input.chars().enumerate() { + for (i, c) in input.char_indices() { if !(c == '(' || c == ')') || !in_str { match c { '(' => nested += 1, diff --git a/askama_parser/src/tests.rs b/askama_parser/src/tests.rs index ce300d3..c23d13f 100644 --- a/askama_parser/src/tests.rs +++ b/askama_parser/src/tests.rs @@ -788,3 +788,10 @@ fn test_parse_array() { )], ); } + +#[test] +fn fuzzed_unicode_slice() { + let d = "{eeuuu{b&{!!&{!!11{{ + 0!(!1q҄א!)!!!!!!n!"; + assert!(Ast::from_str(d, &Syntax::default()).is_err()); +} -- cgit