From a3633879e302f5fd9034a17b9520fdf8c1b18ff9 Mon Sep 17 00:00:00 2001 From: vallentin Date: Tue, 5 Jan 2021 15:30:37 +0100 Subject: Fixed precedence of filters and unary operators (fixes #424) --- askama_shared/src/parser.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 275c92b..58f29f6 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -539,7 +539,7 @@ fn filter(i: &[u8]) -> IResult<&[u8], (&str, Option>)> { } fn expr_filtered(i: &[u8]) -> IResult<&[u8], Expr> { - let (i, (obj, filters)) = tuple((expr_index, many0(filter)))(i)?; + let (i, (obj, filters)) = tuple((expr_unary, many0(filter)))(i)?; let mut res = obj; for (fname, args) in filters { @@ -557,7 +557,7 @@ fn expr_filtered(i: &[u8]) -> IResult<&[u8], Expr> { } fn expr_unary(i: &[u8]) -> IResult<&[u8], Expr> { - let (i, (op, expr)) = tuple((opt(alt((ws(tag("!")), ws(tag("-"))))), expr_filtered))(i)?; + let (i, (op, expr)) = tuple((opt(alt((ws(tag("!")), ws(tag("-"))))), expr_index))(i)?; Ok(( i, match op { @@ -605,7 +605,7 @@ macro_rules! expr_prec_layer { } } -expr_prec_layer!(expr_muldivmod, expr_unary, "*", "/", "%"); +expr_prec_layer!(expr_muldivmod, expr_filtered, "*", "/", "%"); expr_prec_layer!(expr_addsub, expr_muldivmod, "+", "-"); expr_prec_layer!(expr_shifts, expr_addsub, ">>", "<<"); expr_prec_layer!(expr_band, expr_shifts, "&"); -- cgit