StubbleOrg / Stubble

Trimmed down {{mustache}} templates in .NET
Other
401 stars 58 forks source link

Compiled renderer ignores truthy conditions #80

Closed janhohenheim closed 4 years ago

janhohenheim commented 4 years ago

MCVE:

var stubbleRenderer = new StubbleCompilationBuilder().Build();
var render = stubbleRenderer.Compile<Dummy>("{{#Condition}}foo{{/Condition}}");
var view = render(new Dummy());
// view is now string.Empty

public class Dummy
{
    public string Condition { get; } = "Truthy value"
}

When using the default renderer, this code renders "foo". However, the compiled renderer sees Condition as false and doesn't render anything.

Romanx commented 4 years ago

Hi there,

Thanks again for the great reproduction, while unpicking this I found plenty of other cases where this didn't work, our test coverage was lacking and we just lacked feature parity with the standard renderer.

I've changed how the truthy checks work, added more test coverage around that area and at the same time simplified some of the generated code.

I'll aim to get this released tomorrow. Thanks for opening this issue and let us know if you have any other issues.

Romanx commented 4 years ago

@jnferner Thanks very much for reporting this. It has been fixed in release 1.6.3 and has now been released on nuget.

Please let us know if you have any other issues.

janhohenheim commented 4 years ago

Thanks for the quick fixes :)