Skip to content

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

Closed

Description

@bascoder

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 = @"\\\\".

Activity

  1. oformaniuk commented on Jul 27, 2021

    @oformaniuk
    Member

    Duplicate/related: #349

  2. oformaniuk commented on Jul 27, 2021

    @oformaniuk
    Member

    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).

  3. oformaniuk commented on Jul 27, 2021

    @oformaniuk
    Member

    #348
    -- may be used as a starting point for the fix.

  4. oformaniuk commented on Nov 9, 2021

    @oformaniuk
    Member

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

  5. added this to the v3 milestone on Dec 22, 2021
  6. added a commit that references 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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions