Fix: Autoescape does not work well across blocks/inheritance #1909
+108
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
As compiled Jinja Blocks does not have info about parent template scopes like autoescape,
due to which it is ignoring those inherited properties.
Fix:
Fixed the compiler. We made blocks compilation volatile so that it will figure out the correct
property during rendering time.
Issue:
Ideally, the child template body should contain blocks as the first child. because only blocks in the
child template will be replaced with the blocks in the main template.
but whenever the developers write blocks inside other Scoped Nodes, the block is compiled as a part of scoped Node
code by the Jinja compiler. Once the child template is compiled, then the Jinja compiler complies all blocks separately
as well.
Due to this behaviour blocks were compiled multiple times. once when they are part of a scoped node's body and again
when all blocks are compiled. This behaviour leads to unexpected results
Fix:
Fixed Node Parser. So each node in the child template body is inspected to
identify the first block node and move it into the template body. (to avoid multiple parsing of blocks.)
These blocks will be seamlessly placed in the main template body.
Because outer scoped nodes of blocks do not make any scene for the child template as only data inside
blocks will be replaced in the main template.
Checklist:
CHANGES.rst
summarizing the change and linking to the issue... versionchanged::
entries in any relevant code docs.pre-commit
hooks and fix any issues.pytest
andtox
, no tests failed.