Skip to content

Add stricter checking to "from ... import ..."#618

Merged
davidism merged 2 commits intopallets:masterfrom
jackwilsdon:stricter-from-parsing
Jul 7, 2017
Merged

Add stricter checking to "from ... import ..."#618
davidism merged 2 commits intopallets:masterfrom
jackwilsdon:stricter-from-parsing

Conversation

@jackwilsdon
Copy link
Copy Markdown
Contributor

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 PR ensures only name values are allowed as the first value and any values after commas in the import section.

Sadly this may be a "semi-breaking" change, as it removes some functionality that should have never existed and hopefully nobody relies on.

Copy link
Copy Markdown
Member

@davidism davidism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs test. Otherwise, seems fine to me. Waiting for feedback from another maintainer.

@mitsuhiko
Copy link
Copy Markdown
Contributor

Basically needs tests.

@ThiefMaster
Copy link
Copy Markdown
Member

@jackwilsdon are you still interested in your PR and willing to provide tests?

jackwilsdon and others added 2 commits July 7, 2017 08:42
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.
@davidism davidism merged commit a361b74 into pallets:master Jul 7, 2017
@jackwilsdon jackwilsdon deleted the stricter-from-parsing branch September 17, 2018 00:25
@jackwilsdon jackwilsdon restored the stricter-from-parsing branch September 17, 2018 00:25
@jackwilsdon jackwilsdon deleted the stricter-from-parsing branch September 17, 2018 00:25
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants