Skip to content

Subexpression encoding/escaping issue #543

Closed

Description

@jcachat

I am having an issue with a subexpression being encoded/escaped when I have something like this:

{{func1 (func2)}}

where func1 and func2 are helpers I have defined.

Prior to v2, this was working fine as long as func2 did "writer.Write(output)". In v2, I can make this work if I change that to "writer.Write(output, false)". But then I have issues if I try to use func2 on it's own like this:

{{func2}}

I can't find any way in v2 to make this work consistently. Is this a bug? Or is there some way I can know inside func2 whether it is being used in a subexpression?

Activity

  1. oformaniuk commented on Mar 4, 2023

    @oformaniuk
    Member

    @jcachat , can you please provide test to reproduce the issue?

  2. jcachat commented on Mar 4, 2023

    @jcachat
    Author

    This demonstrates it:

            [Fact]
            public void SubExpressionsEncoding()
            {
                var handlebars = Handlebars.Create();
                handlebars.RegisterHelper("func1", (writer, context, args) => {
                    writer.Write(args[0]);
                });
    
                handlebars.RegisterHelper("func2", (writer, context, args) => {
                    writer.Write("test&test");
                });
    
                var template = handlebars.Compile("{{func2}}");
                var output = template(new { });
                Assert.Equal("test&test", output);
    
                //  This test will pass if you change func2 to writer.Write("test&test", false) but then the first test fails
                template = handlebars.Compile("{{func1 (func2)}}");
                output = template(new { });
                Assert.Equal("test&test", output);
            }
  3. added 2 commits that reference this issue on Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions