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

Empty variables result in errors and default not working? #570

Open
Attacler opened this issue Dec 13, 2024 · 0 comments
Open

Empty variables result in errors and default not working? #570

Attacler opened this issue Dec 13, 2024 · 0 comments

Comments

@Attacler
Copy link

liquid-rust version: 0.26.9
rust version: rustc 1.82.0
OS: Windows

If i pass in an empty object but the template tries to read the variable, it will crash.
Reproduction of my issue:

pub fn render_template(template: String, globals: liquid::Object) -> String{
    let template = liquid::ParserBuilder::with_stdlib()
        .build()
        .unwrap()
        .parse(&template)
        .unwrap();

    let output = template.render(&globals).unwrap();

    return output;
}

render_template(
   "Liquid! {{ product_price | default: 2.99 }}".to_string(),
   liquid::Object::new(),
);

The error:

called `Result::unwrap()` on an `Err` value: Error { inner: InnerError { msg: "Unknown variable", user_backtrace: [Trace { trace: None, context: [("requested variable", "product_price")] }], cause: None } }note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Maybe i missed something but shouldent the output be the default value?
As stated on https://liquidjs.com/filters/default.html
Also, if the variable isnt there and default is not provided, shouldent there be nothing at all instead of crashing?

I might be in the wrong, so please correct me if i am!

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