Skip to content

Commit

Permalink
Add stricter checking to "from ... import ..."
Browse files Browse the repository at this point in the history
Currently token parsing on "from ... import ..." is rather "loose" — it
sees the following "invalid" code as perfectly valid:

  {% from "functions" import my_function, %}
  {% from "functions" import, %}
  {% from "functions" import %}

This is caused by the parser ignoring non-name values where there should
be names, either as the first value or after commas.

This commit ensures only name values are allowed as the first value and
any values after commas in the import section.
  • Loading branch information
jackwilsdon authored and davidism committed Jul 7, 2017
1 parent 2c61df1 commit 5d79372
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion jinja2/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def parse_context():
if parse_context() or self.stream.current.type != 'comma':
break
else:
break
self.stream.expect('name')
if not hasattr(node, 'with_context'):
node.with_context = False
self.stream.skip_if('comma')
Expand Down

0 comments on commit 5d79372

Please sign in to comment.