Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine
MIT License
1.24k stars 214 forks source link

IndexOutOfRangeException during execution of compiled templates #484

Closed abraham-fox closed 2 years ago

abraham-fox commented 2 years ago

Describe the bug

Handlebars.net throws IndexOutOfRangeException from HandlebarsDotNet.PathStructure.PathResolver.ResolvePath() on execution of compiled templates that have loose closing blocks.

Examples of templates: {{#if 0}}test{{/if}}{{/unless}} {{#if 1}}{{#unless 0}}test{{/if}}{{/unless}}{{/if}}

Expected behavior:

Handlebars.net compiler should catch this type of template errors during parsing and building expression trees and throw HandlebarsCompilerException with a meaningful error message.

Test to reproduce

[Fact]
public void TestLooseClosingBlockExpressionException()
{ 
    Assert.Throws<HandlebarsCompilerException>(() =>
    {
        Handlebars.Compile("{{#if 0}}test{{/if}}{{/unless}}")(new { });
    });
}