Skip to content

Issue: Using escaped strings is not working correctly #163

@hypetsch

Description

@hypetsch

In issue #65 some issues regarding the usage of escaped strings have been fixed. I am currently facing another issue in combination with escaped characters (backslashes and quotation marks).
TextParser.cs seems to not handle those scenarios correctly.
I have been able to reproduce the issue in unit tests:

[Fact]
public void ParseLambda_StringLiteral_Backslash()
{
    string expectedLeftValue = "Property1.IndexOf(\"\\\")";
    string expectedRightValue = "0";
    var expression = DynamicExpressionParser.ParseLambda(
        new[] { Expression.Parameter(typeof(string), "Property1") },
        typeof(Boolean),
        string.Format("{0} >= {1}", expectedLeftValue, expectedRightValue));

    string leftValue = ((BinaryExpression)expression.Body).Left.ToString();
    string rightValue = ((BinaryExpression)expression.Body).Right.ToString();
    Assert.Equal(typeof(Boolean), expression.Body.Type);
    Assert.Equal(expectedLeftValue, leftValue);
    Assert.Equal(expectedRightValue, rightValue);
}

[Fact]
public void ParseLambda_StringLiteral_QuotationMark()
{
    string expectedLeftValue = "Property1.IndexOf(\"\\\"\")";
    string expectedRightValue = "0";
    var expression = DynamicExpressionParser.ParseLambda(
        new[] { Expression.Parameter(typeof(string), "Property1") },
        typeof(Boolean),
        string.Format("{0} >= {1}", expectedLeftValue, expectedRightValue));

    string leftValue = ((BinaryExpression)expression.Body).Left.ToString();
    string rightValue = ((BinaryExpression)expression.Body).Right.ToString();
    Assert.Equal(typeof(Boolean), expression.Body.Type);
    Assert.Equal(expectedLeftValue, leftValue);
    Assert.Equal(expectedRightValue, rightValue);
}

I think the issue is that the current implementation assumes that it is always a full string (starting and ending with an escaped quotation mark) and not only a single escaped character.

Edit: Updated unit tests code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions