zzzprojects / System.Linq.Dynamic.Core

The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
https://dynamic-linq.net/
Apache License 2.0
1.55k stars 228 forks source link

ParseException after update from v.1.0.8.18 to 1.0.9.0 or any newer (till 1.3.7) #757

Closed OlegNadymov closed 9 months ago

OlegNadymov commented 10 months ago

1. Description

I have string expressions with inner string statements, e.g.:

StaticHelper.First(StaticHelper.SubSelect("Identity", "AdditionalProcessState", "Code = ""New"" ", ""))

The class:

public static class StaticHelper
{
    public static Guid? GetGuid(string name)
    {
        return Guid.NewGuid();
    }
    public static SqlExpression SubSelect(string columnName, string objectClassName, string filter, string order)
    {
        return new SqlExpression();
    }

    public static object First(SqlExpression sqlExpression)
    {
        return Guid.NewGuid().ToString();
    }
}

public class SqlExpression
{
}

This class is already used in TestCustomTypeProvider of your test class DynamicExpressionParserTests.

I try to parse the expression this way:

var exp = @"StaticHelper.First(StaticHelper.SubSelect(""Identity"", ""AdditionalProcessState"", ""Code = """"New"""" "", ""Order""))";
var lambda = DynamicExpressionParser.ParseLambda(config, typeof(User), null, exp);

2. Exception

Message: 

    System.Linq.Dynamic.Core.Exceptions.ParseException : ')' or ',' expected

Stack Trace: 

    TextParser.ValidateToken(TokenId tokenId, String errorMessage) line 451
    ExpressionParser.ParseArgumentList() line 2167
    ExpressionParser.ParseMemberAccess(Type type, Expression expression) line 1794
    ExpressionParser.ParseTypeAccess(Type type, Boolean getNext) line 1701
    ExpressionParser.ParseIdentifier() line 976
    ExpressionParser.ParsePrimaryStart() line 843
    ExpressionParser.ParsePrimary() line 811
    ExpressionParser.ParseUnary() line 806
    ExpressionParser.ParseArithmetic() line 751
    ExpressionParser.ParseAdditive() line 718
    <25 more frames...>
    ExpressionParser.ParseOrOperator() line 290
    ExpressionParser.ParseLambdaOperator() line 270
    ExpressionParser.ParseNullCoalescingOperator() line 257
    ExpressionParser.ParseConditionalOperator() line 241
    ExpressionParser.Parse(Type resultType, Boolean createParameterCtor) line 156
    DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values) line 121
    DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values) line 98
    DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, Type itType, Type resultType, String expression, Object[] values) line 357
    DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Type itType, Type resultType, String expression, Object[] values) line 319

3. Fiddle or Project

I have done changes in DynamicExpressionParserTests adding SqlExpression, StaticHelper.SubSelect, StaticHelper.First locally only to check the first version where I can't parse my expressions. I have not done any PR.

4. Any further technical details

It is working on v.1.0.8.18. But it is not working on versions since 1.0.9.0 till the latest 1.3.7.

I want to upgrade to the latest version because of:

Warning As Error: Package 'System.Linq.Dynamic.Core' 1.0.8.18 has a known critical severity vulnerability, https://github.com/advisories/GHSA-w65q-jcmv-28gj
StefH commented 9 months ago

https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/758

StefH commented 9 months ago

@OlegNadymov It should be fixed.

please try preview NuGet from https://www.myget.org/F/system-linq-dynamic-core/api/v3/index.json

OlegNadymov commented 9 months ago

@OlegNadymov It should be fixed.

please try preview NuGet from https://www.myget.org/F/system-linq-dynamic-core/api/v3/index.json

@StefH thank you! I'll be able to check tomorrow. I'll let you know.

OlegNadymov commented 9 months ago

@StefH I've done several tests. Everything is Ok! 👍 When are you going to release this fix?

StefH commented 9 months ago

I cannot give an indication when this will be released, for now use that preview version.

OlegNadymov commented 9 months ago

Ok. Thank you!

OlegNadymov commented 9 months ago

@StefH I did more tests. Unfortunately, the new version still does not work with more complex expressions. I'll make a new issue with the demo. Here: https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/759