Skip to content

Compiled templates / Detection of recursion in partials is too restrictive #110

@pysco68

Description

@pysco68

Hello,

I was struggling while trying to use a partial more than once within the same compiled template. The compiler raises the exception "Unsupported: Compiled recursive templates will be supported in a later release" as it thinks (erroneously) that there is a recursion in the partial.

Here's a test case that raises the error:

[Test]
public void Partials_Multiple_Usage()
{
    var template = Template("{{>text}} after partial {{>text}}");
    var compiled = template.Compile<TestObject>(name =>
        name == "text" ? Template("{{TestString}} {{#Sub.TestBool}}I am in you{{/Sub.TestBool}}") : null);
    var result = compiled(new TestObject { TestString = "a", Sub = new SubObject { TestBool = true } });
    Assert.AreEqual("a I am in you after partial a I am in you", result);
}

IMO. the problem is that the recusion check in CompileContext.cs (line 198-199) is not really checking for recursion, rather for multiple inclusion. An those are legal in Mustache as far as I know.

I'll try to provide a true recursion check in the next days if you'd like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions