Skip to content

Commit

Permalink
Accept trailing comma in array
Browse files Browse the repository at this point in the history
Fix #1086
  • Loading branch information
aquarhead authored and djc committed Sep 28, 2024
1 parent 6d751f9 commit aa28384
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion askama_parser/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions testing/tests/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}",
Expand Down

0 comments on commit aa28384

Please sign in to comment.