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

Using a custom helper in a escaped string, and escaping a string argument to that helper is not handled correctly by Handlebars.Net #584

Open
StefH opened this issue May 29, 2024 · 0 comments
Labels

Comments

@StefH
Copy link
Collaborator

StefH commented May 29, 2024

Describe the bug

A clear and concise description of what the bug is.

Expected behavior:

A clear and concise description of what you expected to happen.

Working unit-test

[Fact]
    public void SelectToken_WithComplexTemplate()
    {
        // Arrange
        const string requestAsJson = """
        {
          "bodyAsJson": {
            "pricingContext": {
              "market": "US"
            }
          }
        }
        """;
        var request = JsonConvert.DeserializeObject(requestAsJson);

        // Use single quotes for the JsonPath else it will be parsed correctly by Handlebars.Net
        var action = _handlebarsContext.Compile("{\r\n  \"market\": \"{{JsonPath.SelectToken bodyAsJson '$.pricingContext.market'}}\",\r\n  \"languages\": \"en\"\r\n}");

        // Act
        var result = action(request);

        // Assert
        var expected = """
        {
          "market": "US",
          "languages": "en"
        }
        """;
        result.Should().Be(expected);
    }

Using escaped double quotes does not work:

"{\r\n  \"market\": \"{{JsonPath.SelectToken bodyAsJson \\\"$.pricingContext.market'}}\\\",\r\n  \"languages\": \"en\"\r\n}"

Exception:
System.NullReferenceException : Object reference not set to an instance of an object.

Linked to
WireMock-Net/WireMock.Net#1108

@StefH StefH added the bug label May 29, 2024
@StefH StefH changed the title Using a custom helper in a esacped string, and escaping a string argument to that helper is not handled correctly by Handlebars.Net Using a custom helper in a escaped string, and escaping a string argument to that helper is not handled correctly by Handlebars.Net May 29, 2024
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

1 participant