Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Subexpression encoding/escaping issue

jcachat opened this issue · comments

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?

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

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);
        }