From: Jack Wilsdon Date: Sun, 30 Oct 2016 22:11:21 +0000 (+0000) Subject: Add stricter checking to "from ... import ..." X-Git-Tag: 2.10~15^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d793726404cc549b4006cb0a98a428d50173062;p=thirdparty%2Fjinja.git Add stricter checking to "from ... import ..." 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. --- diff --git a/jinja2/parser.py b/jinja2/parser.py index 6d1fff6a..08233642 100644 --- a/jinja2/parser.py +++ b/jinja2/parser.py @@ -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')