Skip to content

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

Description

@markdebhailis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions