pieterderycke / Jace

Jace.NET is a calculation engine for the .NET platform.
MIT License
436 stars 94 forks source link

expressions with variable names having $ sign, returning wrong results. #7

Closed abdul-qadirdeveloper closed 10 years ago

abdul-qadirdeveloper commented 10 years ago

I provided expression $1+$2+$3 and variables list as follows $1=0 $2=0 $3=0 it should return 0, but it returned 6.

rummelsworth commented 10 years ago

I believe Jace.Tokenizer.TokenReader.IsPartOfVariable is the only logic that discerns what characters are valid as parts of variable names. The only acknowledged characters are alphanumeric with the restriction that numeric characters cannot begin the variable name.

Jace.NET simply ignores $ characters (among some others), so your input expression is basically read as "1+2+3". So this isn't really wrong behavior so much as it is a feature request to support $ as a valid character in variable names.

To implement this yourself, I believe you can just add a clause to the or-chain in IsPartOfVariable to check whether the character is equal to $. I did so and it worked for me.

pieterderycke commented 10 years ago

This is fixed in Jace 0.8.7. It will no longer silently ignore invalid characters, but it will now throw a ParseException.