Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix Issue #100, tailing commas in macros args

This change will allow trailing commas in macro definitions, and in
calls to macros.
  • Loading branch information...
commit 7b2f7188dcb7717fcc99ac26a85a81582e20f698 1 parent f6f3704
@njl authored
Showing with 8 additions and 0 deletions.
  1. +2 −0  jinja2/parser.py
  2. +6 −0 jinja2/testsuite/core_tags.py
View
2  jinja2/parser.py
@@ -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'):
View
6 jinja2/testsuite/core_tags.py
@@ -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 %}\
Please sign in to comment.
Something went wrong with that request. Please try again.