diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml index 4a676443..b1c3981f 100644 --- a/askama_derive/Cargo.toml +++ b/askama_derive/Cargo.toml @@ -25,7 +25,7 @@ with-rocket = [] with-warp = [] [dependencies] -parser = { package = "askama_parser", version = "0.3", path = "../askama_parser" } +parser = { package = "askama_parser", version = "0.3.1", path = "../askama_parser" } mime = "0.3" mime_guess = "2" proc-macro2 = "1" diff --git a/askama_derive/src/config.rs b/askama_derive/src/config.rs index 599d5a24..19358371 100644 --- a/askama_derive/src/config.rs +++ b/askama_derive/src/config.rs @@ -7,6 +7,7 @@ use std::{env, fs}; use serde::Deserialize; use crate::{CompileError, CRATE}; +use parser::expr::TWO_PLUS_CHAR_OPS; use parser::node::Whitespace; use parser::Syntax; @@ -147,20 +148,23 @@ impl<'a> TryInto> for RawSyntax<'a> { comment_end: self.comment_end.unwrap_or(default.comment_end), }; - for s in [ - syntax.block_start, - syntax.block_end, - syntax.expr_start, - syntax.expr_end, - syntax.comment_start, - syntax.comment_end, + for (s, kind) in [ + (syntax.block_start, "block_start"), + (syntax.block_end, "block_end"), + (syntax.expr_start, "expr_start"), + (syntax.expr_end, "expr_end"), + (syntax.comment_start, "comment_start"), + (syntax.comment_end, "comment_end"), ] { if s.len() < 2 { - return Err( - format!("delimiters must be at least two characters long: {s:?}").into(), - ); + return Err(format!( + "{kind} delimiter must be at least two characters long: {s:?}" + ) + .into()); } else if s.chars().any(|c| c.is_whitespace()) { - return Err(format!("delimiters may not contain white spaces: {s:?}").into()); + return Err(format!("{kind} delimiter may not contain whitespace: {s:?}").into()); + } else if TWO_PLUS_CHAR_OPS.contains(&s) { + return Err(format!("{kind} delimiter may not contain operators: {s:?}").into()); } } @@ -486,7 +490,7 @@ mod tests { let config = Config::new(raw_config, None); assert_eq!( config.unwrap_err().msg, - r#"delimiters must be at least two characters long: "<""#, + r#"block_start delimiter must be at least two characters long: "<""#, ); let raw_config = r#" @@ -497,7 +501,7 @@ mod tests { let config = Config::new(raw_config, None); assert_eq!( config.unwrap_err().msg, - r#"delimiters may not contain white spaces: " {{ ""#, + r#"block_start delimiter may not contain whitespace: " {{ ""#, ); let raw_config = r#" diff --git a/askama_parser/Cargo.toml b/askama_parser/Cargo.toml index 789a41fc..92727a91 100644 --- a/askama_parser/Cargo.toml +++ b/askama_parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "askama_parser" -version = "0.3.0" +version = "0.3.1" description = "Parser for Askama templates" documentation = "https://docs.rs/askama" keywords = ["markup", "template", "jinja2", "html"] diff --git a/askama_parser/src/expr.rs b/askama_parser/src/expr.rs index 16069b2d..4ea4fe60 100644 --- a/askama_parser/src/expr.rs +++ b/askama_parser/src/expr.rs @@ -172,6 +172,7 @@ impl<'a> Expr<'a> { ))(i) } + // Keep in sync with `TWO_PLUS_CHAR_OPS`, below expr_prec_layer!(or, and, "||"); expr_prec_layer!(and, compare, "&&"); expr_prec_layer!(compare, bor, "==", "!=", ">=", ">", "<=", "<"); @@ -430,3 +431,6 @@ impl<'a> Suffix<'a> { map(preceded(take_till(not_ws), char('?')), |_| Self::Try)(i) } } + +pub const TWO_PLUS_CHAR_OPS: &[&str] = + &["||", "&&", "==", "!=", ">=", "<=", "<<", ">>", "..", "..="];