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

Whitespace not stripped in else branch of for loop #862

Open
traviscross opened this issue Oct 10, 2023 · 0 comments
Open

Whitespace not stripped in else branch of for loop #862

traviscross opened this issue Oct 10, 2023 · 0 comments

Comments

@traviscross
Copy link

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");
}
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

1 participant