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

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

Open
markdebhailis opened this issue Oct 24, 2023 · 0 comments
Labels

Comments

@markdebhailis
Copy link

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.

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

No branches or pull requests

1 participant