Skip to content

Commit

Permalink
Fix Issue pallets#100, tailing commas in macros args
Browse files Browse the repository at this point in the history
This change will allow trailing commas in macro definitions, and in
calls to macros.
  • Loading branch information
njl committed Mar 13, 2012
1 parent f6f3704 commit 7b2f718
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jinja2/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def parse_signature(self, node):
while self.stream.current.type != 'rparen':
if args:
self.stream.expect('comma')
if self.stream.current.type == 'rparen':
break
arg = self.parse_assign_target(name_only=True)
arg.set_ctx('param')
if self.stream.skip_if('assign'):
Expand Down
6 changes: 6 additions & 0 deletions jinja2/testsuite/core_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ def test_arguments(self):
{{ m() }}|{{ m('a') }}|{{ m('a', 'b') }}|{{ m(1, 2, 3) }}''')
assert tmpl.render() == '||c|d|a||c|d|a|b|c|d|1|2|3|d'

def test_trailing_comma(self):
tmpl = self.env.from_string('''\
{% macro m(a, b,) %}{{ a }}|{{ b }}{% endmacro %}
{{ m(1,2,) }}''')
assert tmpl.render() == '1|2'

def test_varargs(self):
tmpl = self.env.from_string('''\
{% macro test() %}{{ varargs|join('|') }}{% endmacro %}\
Expand Down

0 comments on commit 7b2f718

Please sign in to comment.