Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine
MIT License
1.26k stars 217 forks source link

HandleBars.Compile replaces '\\' (double backslash) with '\' single backslash #462

Open bascoder opened 3 years ago

bascoder commented 3 years ago

What

When the template contains a double backslash. The result only contains a single backslash.

Reproduction

To reproduce I wrote the following unit test:

[TestMethod]
public void Compile_WithDoubleBackslashes_ReturnsExpectedString()
{
    string template = @"\\";

    var compiledTemplate = Handlebars.Compile(template);
    string result = compiledTemplate(null);

    Assert.AreEqual(@"\\", result);
}

It fails with message: Assert.AreEqual failed. Expected:<\\>. Actual:<\>.

Here I would expect that the result string contains the double backslash.

Workaround

To workaround this issue I can change the template to string template = @"\\\\".

oformaniuk commented 3 years ago

Duplicate/related: https://github.com/Handlebars-Net/Handlebars.Net/issues/349

oformaniuk commented 3 years ago

May be considered as a breaking change as this was the behavior from the day one and many users may be impacted. Fix may require feature flag to switch to new behavior (or to previous behavior, up to the contributor).

oformaniuk commented 3 years ago

https://github.com/Handlebars-Net/Handlebars.Net/pull/348 -- may be used as a starting point for the fix.

oformaniuk commented 2 years ago

Hello @xcskilab Can you provide more details on your question as I'm not completely sure what context you're asking in?