Keats / tera

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

Whitespace not stripped in `else` branch of `for` loop #862

Open traviscross opened 11 months ago

traviscross commented 11 months ago

Tera v1.19.1 fails to strip whitespace in the else branch of a for loop. I.e., this template...

{% for x in [] -%}
{% else -%}
B
{% endfor -%}

...produces \nB\n when it should produce B\n. Here's a failing test:

//! ```cargo
//! [dependencies.tera]
//! version = "=1.19.1"
//! ```

use tera::{Context, Tera};

#[test]
fn can_remove_whitespace_for_else() {
    let mut tera = Tera::default();
    tera.add_raw_templates(vec![
        ("a.html", "{% for x in [] -%}{% else -%}\nB\n{% endfor -%}"),
    ]).unwrap();
    assert_eq!(tera.render("a.html", &Context::new()).unwrap(), "B\n");
}