zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
449 stars 86 forks source link

Eval.Tokenize throws NullReferenceException if a variable starts with _ and the next character is a number #118

Closed fidke closed 2 years ago

fidke commented 2 years ago

For example if the variable name is _1, this is valid c# code that compiles but Eval.Tokenize will throw an exception if it encounters the _1 variable:

var _1 = 1;
if(_1 > 1) { /* do something */ }

STR:

Eval.Tokenize("_1 > 1");

Throws exception:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at ?.?(StringBuilder ?)
   at Z.Expressions.CodeAnalysis.CSharp.SyntaxParser.Tokenize(SyntaxParserOptions options, String code)
   at Z.Expressions.EvalContext.Tokenize(String code) ...
fidke commented 2 years ago

Tested in version 4.0.63

JonathanMagnan commented 2 years ago

Hello @fidke ,

Thank you for reporting, we support _a (followed by a char) but not _1 (followed by a number).

This is probably something we missed and should not be hard to fix.

One of my developers will look at it.

Best Regards,

Jon

JonathanMagnan commented 2 years ago

Hello @fidke ,

The v4.0.64 has been released.

We fixed many cases in which the _ was not working as expected.

Let us know if everything is working on your side.

Best Regards,

Jon