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

undeclared_variables() stuck with for loop ({% for ... in ... %}) #484

Closed
gemhtcr opened this issue Apr 9, 2024 · 0 comments · Fixed by #486
Closed

undeclared_variables() stuck with for loop ({% for ... in ... %}) #484

gemhtcr opened this issue Apr 9, 2024 · 0 comments · Fixed by #486

Comments

@gemhtcr
Copy link

gemhtcr commented Apr 9, 2024

Description

minijinja undeclared_variables() stucks when there is a variable in for loop

[What happened]
The running code stuck and never exited

Reproduction steps

// main.rs
// Running the code below
fn main() {
    let mut env = minijinja::Environment::new();
    env.add_template("my_test", {
        r#"
            {% for item in content.products.items() %}
              {{ foo.bar }}                          
              {{ item.name }}  // remove this line and it will run to exit
            {% endfor %}
        "#
    })
    .unwrap();
    let tpl = env.get_template("my_test").unwrap();
    println!("check point 1");
    let ret = tpl.undeclared_variables(true);     <-- stuck here
    println!("check point 2, ret={:?}", ret);    <-- never see this
}
# Cargo.toml
[package]
name = "undeclared_variables_stuck_issue"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
minijinja = "1.0.17"

Additional helpful information:

  • Version of minijinja:
1.0.17
  • Version of rustc:
rustc 1.76.0 (07dca489a 2024-02-04)
  • Operating system and version:
ProductName:            macOS
ProductVersion:         14.2.1
BuildVersion:           23C71
  • If set nested param to false, it's able to run to exit

What did you expect

When running the code above, I expect to see

check point 1
check point 2, ret={"foo.bar", "content.products.items"}
# Note that the output didn't have `item.name` 
# cause it's a declared variable in for loop

[What you think should have happened]
The cpu is high (20 % v.s 5%) all time when running the code above, I guess it might enter an infinite cyclic loop

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

Successfully merging a pull request may close this issue.

2 participants