Skip to content

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

@Attacler

Description

@Attacler

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions