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

Subexpression encoding/escaping issue #543

Open
jcachat opened this issue Mar 3, 2023 · 2 comments
Open

Subexpression encoding/escaping issue #543

jcachat opened this issue Mar 3, 2023 · 2 comments
Labels

Comments

@jcachat
Copy link

jcachat commented Mar 3, 2023

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 jcachat added the bug label Mar 3, 2023
@oformaniuk
Copy link
Member

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

@jcachat
Copy link
Author

jcachat commented Mar 4, 2023

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

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

2 participants