Handlebars.Net icon indicating copy to clipboard operation
Handlebars.Net copied to clipboard

The behaviour of `WriteSafeString` changes depending on when my helper is registered

Open markdebhailis opened this issue 3 years ago • 0 comments

Describe the bug

The behaviour of WriteSafeString changes depending on when my helper is registered

Expected behavior:

A clear and concise description of what you expected to happen.

Test to reproduce

public class WriteSafeStringTest
{
    [Fact]
    public void ItAllowsLateBindingOfHelpers()
    {
        // Arrange
        HandlebarsHelper link_to = (writer, context, parameters) =>
        {
            writer.WriteSafeString($"<a href='{context["url"]}'>{context["text"]}</a>");
        };

        string source = @"Click here: {{link_to}}";

        var data = new
        {
            url = "https://github.com/rexm/handlebars.net",
            text = "Handlebars.Net"
        };

        // Act
        var handlebars1 = HandlebarsDotNet.Handlebars.Create();
        handlebars1.RegisterHelper("link_to", link_to);
        var template1 = handlebars1.Compile(source);
        var result1 = template1(data);

        var handlebars2 = HandlebarsDotNet.Handlebars.Create();
        var template2 = handlebars2.Compile(source);
        handlebars2.RegisterHelper("link_to", link_to);
        var result2 = template2(data);

        // Assert
        Assert.Equal(result1, result2);
    }
}

Other related info

Provide additional information if any.


After submitting the issue

Please consider contributing to the project by submitting a PR with a fix to the issue. This would help to solve your problem in a shorter time as well as help other users of the project.

In case you do not know where to start - feel free to ask for help in the issue thread.

Building an active community is essential for any project survival as time of maintainers is limited.

markdebhailis avatar Oct 24 '23 11:10 markdebhailis