Skip to content

Panic when generating error object for malformed template #427

Closed
@5225225

Description

@5225225

Reproduction code:

fn main() {
    let s = "{{#>(X)}}{{/X}}";
    let tpl = handlebars::Handlebars::new();
    let _ = tpl.render_template(&s, &Vec::<()>::new());
}

Looks like the actual value of what is in X there doesn't matter (and they don't need to be the same character, but can be).

The rest I couldn't remove without the panic not happening.

Stack trace (when testing the above on the latest version, commit 39589d9):

This happens on both the crates.io version as well as the latest version from git.

return Err(TemplateError::of(
TemplateErrorReason::MismatchingClosedDecorator(
d.name.as_name().unwrap().into(),
close_tag_name.unwrap().into(),
),
)
is where the panic happens, on line 662

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/jess/.cargo/git/checkouts/handlebars-rust-6b5b431bf9aaa55b/39589d9/src/template.rs:662:62
stack backtrace:
   0: rust_begin_unwind
             at /rustc/42816d61ead7e46d462df997958ccfd514f8c21c/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/42816d61ead7e46d462df997958ccfd514f8c21c/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/42816d61ead7e46d462df997958ccfd514f8c21c/library/core/src/panicking.rs:50:5
   3: core::option::Option<T>::unwrap
             at /home/jess/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:386:21
   4: handlebars::template::Template::compile
             at /home/jess/.cargo/git/checkouts/handlebars-rust-6b5b431bf9aaa55b/39589d9/src/template.rs:662:45
   5: handlebars::registry::Registry::render_template_to_write
             at /home/jess/.cargo/git/checkouts/handlebars-rust-6b5b431bf9aaa55b/39589d9/src/registry.rs:555:19
   6: handlebars::registry::Registry::render_template
             at /home/jess/.cargo/git/checkouts/handlebars-rust-6b5b431bf9aaa55b/39589d9/src/registry.rs:523:9
   7: scratchPMtZAxU7Y::main
             at ./src/main.rs:4:13
   8: core::ops::function::FnOnce::call_once
             at /home/jess/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions