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

no escaping template for json #347

Open
ArtemIsmagilov opened this issue Feb 9, 2025 · 3 comments
Open

no escaping template for json #347

ArtemIsmagilov opened this issue Feb 9, 2025 · 3 comments

Comments

@ArtemIsmagilov
Copy link

ArtemIsmagilov commented Feb 9, 2025

I want to upload a json file, but got an error.
This fixed it with escape="none"

Are there any plans to add json escaping?

Example code

use rinja::Template;

#[derive(Template)]
#[template(path = "a.json")]
struct Footer<'a> {
    year: u16,
    enterprise: &'a str,
}

Example error

1. no escaper defined for extension 'json'. The available extensions are: "", "htm", "html", "j2", "jinja", "jinja2", "md", "none", "rinja", "svg", "txt", "xml", "yml"
@ArtemIsmagilov ArtemIsmagilov changed the title no escaping for json no escaping template for json Feb 9, 2025
@Kijewski
Copy link
Collaborator

Kijewski commented Feb 9, 2025

Could you please add an example what "a.json" looks like? I assume that you want to use expressions {{ }} only inside of strings?

@ArtemIsmagilov
Copy link
Author

Hi! Of course!

example a.json

{
  "year": {{year}},
  "enterprise": "{{enterprise}}"
}

@Kijewski
Copy link
Collaborator

Kijewski commented Feb 9, 2025

I think that's a too specialized use case, with too many script-injection hazards. Alas, currently we don't have a good example how to write an escaper. I opened an issue for that: #348.

To make things short: You have to add an empty struct that implements Escaper. Then you must configure the extension "json" to use this escaper.

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

No branches or pull requests

2 participants