mitsuhiko / minijinja

MiniJinja is a powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
https://docs.rs/minijinja/
Apache License 2.0
1.67k stars 101 forks source link

Allow changing undefined behavior #225

Closed mitsuhiko closed 1 year ago

mitsuhiko commented 1 year ago

There are a handful of different undefined behaviors that can be opted into in Jinja2. MiniJinja only supports the default. They look roughly like this:

The way this is implemented in Jinja2 is by creating different instances of the undefined value in the different parts of the engine. It's also possible to have different types of undefined values flying around. This makes not a lot of sense in MiniJinja since we don't always have the environment available where an undefined value is created.

One option would be to have an UndefinedBehavior enum with the following values:

enum UndefinedBehavior {
    Default,
    Strict,
    Chainable,
}

These would map to the behavior above. Operations on Value that are exported via the API would behave like they do today, but the vm would special case undefined behavior as instructed. Likewise env.format would emit an error in strict mode, and so would the for loop or filters like sort or list.

Refs #215 and https://github.com/pallets/jinja/issues/1820

mitsuhiko commented 1 year ago

Fixed by #227.