Skip to content

Finalize should only apply to variable #63#535

Closed
godsarmy wants to merge 1 commit intopallets:masterfrom
godsarmy:fix_finalize_variable
Closed

Finalize should only apply to variable #63#535
godsarmy wants to merge 1 commit intopallets:masterfrom
godsarmy:fix_finalize_variable

Conversation

@godsarmy
Copy link
Copy Markdown

I submit this PR to resolve the issue of #63 as i believe it is incorrect to apply finalize to any value in the template (constant, condition).

I think the root cause is self-explaining in the unit test "<{{ none }} >" as the original implementation tried to change none to empty string. However, none is not a variable in context but a constant, so instead, it should not be applied with finalize function.

tmpl = env.from_string('<{{ none }}>')

@5p4k
Copy link
Copy Markdown

5p4k commented Oct 24, 2016

As a side remark, if finalize were not to be called on the template source, this would enable a much higher degree of customization -- one could autoescape the variables for languages other than HTML (see e.g. this question on SO, which originally brought me here).

@and1er
Copy link
Copy Markdown

and1er commented Apr 25, 2018

What the status of this PR? Is the problem with LaTeX autoescape still cannot be solved https://stackoverflow.com/q/8001986/7444782 ?

@davidism
Copy link
Copy Markdown
Member

davidism commented Oct 13, 2019

{{ none }} is still an expression, just one that has been optimized to a constant. There is a distinction between static template data and constant expressions. All expressions should pass through finalize, template data should not. See #1080

@davidism davidism added this to the 2.11.0 milestone Oct 13, 2019
@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