]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Add stricter checking to "from ... import ..."
authorJack Wilsdon <jack.wilsdon@gmail.com>
Sun, 30 Oct 2016 22:11:21 +0000 (22:11 +0000)
committerDavid Lord <davidism@gmail.com>
Fri, 7 Jul 2017 15:42:25 +0000 (08:42 -0700)
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.

jinja2/parser.py

index 6d1fff6a9955ae4e2940b00e0adc8b6a357af6b8..08233642d0946696108c9a8aed990e74678ea746 100644 (file)
@@ -334,7 +334,7 @@ class Parser(object):
                 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')