diff options
-rw-r--r-- | askama_parser/src/expr.rs | 2 | ||||
-rw-r--r-- | askama_parser/src/node.rs | 2 | ||||
-rw-r--r-- | testing/tests/macro.rs | 30 |
3 files changed, 32 insertions, 2 deletions
diff --git a/askama_parser/src/expr.rs b/askama_parser/src/expr.rs index 2928b57..65a7835 100644 --- a/askama_parser/src/expr.rs +++ b/askama_parser/src/expr.rs @@ -119,7 +119,7 @@ impl<'a> Expr<'a> { } }), ), - char(')'), + tuple((opt(ws(char(','))), char(')'))), )), )(i) } diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs index 27d4adc..c2f7b39 100644 --- a/askama_parser/src/node.rs +++ b/askama_parser/src/node.rs @@ -493,7 +493,7 @@ impl<'a> Macro<'a> { delimited( ws(char('(')), separated_list0(char(','), ws(identifier)), - ws(char(')')), + tuple((opt(ws(char(','))), char(')'))), )(i) } diff --git a/testing/tests/macro.rs b/testing/tests/macro.rs index 9b3c63d..3d027d2 100644 --- a/testing/tests/macro.rs +++ b/testing/tests/macro.rs @@ -140,3 +140,33 @@ struct OnlyNamedArgument; fn test_only_named_argument() { assert_eq!(OnlyNamedArgument.render().unwrap(), "hi"); } + +// Check for trailing commas. +#[derive(Template)] +#[template( + source = r#"{% macro button(label , ) %} +{{- label -}} +{% endmacro %} +{%- macro button2(label ,) %} +{% endmacro %} +{%- macro button3(label,) %} +{% endmacro %} +{%- macro button4(label, ) %} +{% endmacro %} +{%- macro button5(label ) %} +{% endmacro %} + +{%- call button(label="hi" , ) -%} +{%- call button(label="hi" ,) -%} +{%- call button(label="hi",) -%} +{%- call button(label="hi", ) -%} +{%- call button(label="hi" ) -%} +"#, + ext = "html" +)] +struct TrailingComma; + +#[test] +fn test_trailing_comma() { + assert_eq!(TrailingComma.render().unwrap(), "hihihihihi"); +} |