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

Panic when generating error object for malformed template #427

Closed
5225225 opened this issue May 1, 2021 · 1 comment · Fixed by #429
Closed

Panic when generating error object for malformed template #427

5225225 opened this issue May 1, 2021 · 1 comment · Fixed by #429

Comments

@5225225
Copy link
Contributor

5225225 commented May 1, 2021

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.
@sunng87
Copy link
Owner

sunng87 commented May 2, 2021

Good catch. I will create a fix to address this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants