pallets / jinja

A very fast and expressive template engine.
https://jinja.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.6k forks source link

`tojson` always do autoescape #1934

Open boy2000-007man opened 7 months ago

boy2000-007man commented 7 months ago

tojson always escape ' to \u0027 even if autoescape=False, actually it also happens to <, >, &

>>> import jinja2
>>> env = jinja2.Environment(autoescape=False)
>>> t = env.from_string("{{ x|tojson }}")
>>> print(t.render(x="'"))
"\u0027"

I think the expected output should be "'"

Environment:

boy2000-007man commented 7 months ago

Sorry, but what does not planned mean here? Is it a feature or due to inappropriate setting? Or it's duplicated? Or won't fix?

davidism commented 7 months ago

My bad, didn't mean to close this.

Happy to review a PR, the tojson filter already gets the eval context which has the autoescape state.