diff --git a/askama_parser/src/expr.rs b/askama_parser/src/expr.rs index 4ea4fe60..94f7d404 100644 --- a/askama_parser/src/expr.rs +++ b/askama_parser/src/expr.rs @@ -270,7 +270,7 @@ impl<'a> Expr<'a> { separated_list0(char(','), ws(move |i| Self::parse(i, level))), Self::Array, ), - char(']'), + pair(opt(ws(char(','))), char(']')), )), )(i) } diff --git a/testing/tests/loops.rs b/testing/tests/loops.rs index 4a021538..48ae030d 100644 --- a/testing/tests/loops.rs +++ b/testing/tests/loops.rs @@ -83,6 +83,16 @@ fn test_for_array() { assert_eq!(t.render().unwrap(), "123"); } +#[derive(Template)] +#[template(source = "{% for i in [1, 2, 3, ] %}{{ i }}{% endfor %}", ext = "txt")] +struct ForArrayTailingCommaTemplate; + +#[test] +fn test_for_array_trailing_comma() { + let t = ForArrayTailingCommaTemplate; + assert_eq!(t.render().unwrap(), "123"); +} + #[derive(Template)] #[template( source = "{% for i in [1, 2, 3].iter() %}{{ i }}{% endfor %}",