Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.36k stars 280 forks source link

Round filter does not return int with precision = 0 #889

Open jasger9000 opened 6 months ago

jasger9000 commented 6 months ago

When using the | round filter with precision = 0 to return a natural number, the filter still returns a float leading to unexpected behavior when using it in combination with functions expecting an integer.

Minimal code that does not work

use tera::{Tera, Context};

fn main() {
    let test = Tera::one_off(
        "{% for i in range(end=5.5 | round) %} {{ i }}\n {% endfor %}",
        &Context::new(),
        true
    );

    print!("{test:?}");
}

Output

Err(Error { kind: Msg("Failed to render '__tera_one_off'"), source: Some(Error { kind: CallFunction("range"), source: Some(Error { kind: Msg("Function range received end=6.0 but end can only be a number"), source: None }) }) })