Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't skip an erroneous comma when parsing "from" #617

Merged
merged 2 commits into from Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES
Expand Up @@ -28,11 +28,12 @@ Version 2.10
- Add ``min`` and ``max`` filters. (`#475`_)
- Add tests for all comparison operators: ``eq``, ``ne``, ``lt``, ``le``,
``gt``, ``ge``. (`#665`_)
- ``import`` statement cannot end with a trailing comma. (`#618`_)
- ``import`` statement cannot end with a trailing comma. (`#617`_, `#618`_)

.. _#469: https://github.com/pallets/jinja/pull/469
.. _#475: https://github.com/pallets/jinja/pull/475
.. _#478: https://github.com/pallets/jinja/pull/478
.. _#617: https://github.com/pallets/jinja/pull/617
.. _#618: https://github.com/pallets/jinja/pull/618
.. _#665: https://github.com/pallets/jinja/pull/665

Expand Down
1 change: 0 additions & 1 deletion jinja2/parser.py
Expand Up @@ -337,7 +337,6 @@ def parse_context():
self.stream.expect('name')
if not hasattr(node, 'with_context'):
node.with_context = False
self.stream.skip_if('comma')
return node

def parse_signature(self, node):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_imports.py
Expand Up @@ -75,6 +75,12 @@ def test_trailing_comma_with_context(self, test_env):
test_env.from_string('{% from "foo" import bar, with, context %}')
test_env.from_string('{% from "foo" import bar, with with context %}')

with pytest.raises(TemplateSyntaxError):
test_env.from_string('{% from "foo" import bar,, with context %}')

with pytest.raises(TemplateSyntaxError):
test_env.from_string('{% from "foo" import bar with context, %}')

def test_exports(self, test_env):
m = test_env.from_string('''
{% macro toplevel() %}...{% endmacro %}
Expand Down