Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tojson always do autoescape #1934

Open
boy2000-007man opened this issue Feb 4, 2024 · 2 comments · May be fixed by #1937
Open

tojson always do autoescape #1934

boy2000-007man opened this issue Feb 4, 2024 · 2 comments · May be fixed by #1937

Comments

@boy2000-007man
Copy link

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:

  • Python version: 3.11.4
  • Jinja version: 3.1.2
@davidism davidism closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
@boy2000-007man
Copy link
Author

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
Copy link
Member

davidism commented Feb 5, 2024

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.

@davidism davidism reopened this Feb 5, 2024
@boy2000-007man boy2000-007man linked a pull request Feb 6, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants