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

DynamicExpression parser can't parse when there is a dot in a string #683

Closed
YeskaNova opened this issue Mar 5, 2023 · 8 comments
Closed
Assignees
Labels

Comments

@YeskaNova
Copy link

1. Description

I need to parse a condition that checks that the Name of an entity is "System.Int32" , but because of the dot, I get an error. Could you see why is that happening please? It seems to me that it's a very simple situation.

2. Exception

Unhandled exception. '.' or '(' or string literal expected (at index 19)

3. Fiddle

https://dotnetfiddle.net/hdL13r

@StefH
Copy link
Collaborator

StefH commented Mar 6, 2023

Hello @YeskaNova,

In your example code, the string value in the expression, System.Int32 is parsed as a Type : Int32.

To work around this:

1]
Set the ParsingConfig SupportCastingToFullyQualifiedTypeAsString to false.

2]
Or use the parameterized way from DynamicExpressionParser, see example below:

var expression = DynamicExpressionParser.ParseLambda(typeof(EntityDbo), typeof(bool), "Name == @0", "System.Int32");

#685

@StefH StefH closed this as completed Mar 6, 2023
@StefH StefH self-assigned this Mar 6, 2023
@StefH StefH added the question label Mar 6, 2023
@YeskaNova
Copy link
Author

Why it tries to interpret something within the string quotes ? isn't that a security issue ?

@StefH
Copy link
Collaborator

StefH commented Mar 7, 2023

You mean :

"Name=\"System.Int32\""

?

@YeskaNova
Copy link
Author

Yes, this part "System.Int32" is a string token and should not be interpreted by the interpretor.

@StefH
Copy link
Collaborator

StefH commented Mar 7, 2023

What do you mean by string token?

The whole purpose from this library is to allow dynamic querying using a string expression, like:

var resultDynamic = context.Customers
     .Where("City == \"Paris\"")
    .ToList();

https://dynamic-linq.net/basic-simple-query

@YeskaNova
Copy link
Author

YeskaNova commented Mar 7, 2023

The string token is "System.Int32" .

For example, this code should work:


var resultDynamic = context.Customers
     .Where("City == \"System.Int32\"")
    .ToList();

"Paris" is a string token, and the interpretor should not try to understand what is "inside" the string. Like "1/0" should not be a problem but 1/0 will raise an exception, anything inside a string should not be considered by the interpretor. I don't see any usecase where intepreting inside a string is useful ( and that's not string interpolation )

@StefH StefH reopened this Mar 7, 2023
@StefH StefH added bug and removed question labels Mar 7, 2023
@StefH
Copy link
Collaborator

StefH commented Mar 7, 2023

It will be fixed in next release.

#687

@StefH StefH closed this as completed Mar 7, 2023
@YeskaNova
Copy link
Author

Great, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants