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

if function does not handle empty string as a false condition #100

Open
thetreatment opened this issue Jan 29, 2024 · 1 comment
Open

if function does not handle empty string as a false condition #100

thetreatment opened this issue Jan 29, 2024 · 1 comment
Labels
needs author feedback Needs feedback from the author to be closed or worked on.

Comments

@thetreatment
Copy link
Contributor

This is perhaps a convenience rather than true bug, nonetheless it proves inconvenient.

In the case where the conditional part of an "if" function (function.Expression[0]) returns an empty string, it is not evaluated as false, it simply throws a System.FormatException from Convert.ToBoolean(object, IFormatProvider).

In fact, because of the chosen ToBoolean method used (with a format provider), many of the common true/false values cannot be used, e.g 0/1 (https://learn.microsoft.com/en-us/dotnet/api/system.convert.toboolean?view=net-8.0)

Since throwing and handling Exceptions can be processing expensive when using the Ncalc library over large data sets, it would be better to either handle a variety of values via the ToBoolean overload without a format provider, or by using Boolean.TryParse to cleanly handle cases of failed conversion and null/empty values.

@gumbarros
Copy link
Member

I think you will need to handle empty values at OnEvaluateParameter, because an empty string is not really a false value.

@gumbarros gumbarros added the needs author feedback Needs feedback from the author to be closed or worked on. label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs author feedback Needs feedback from the author to be closed or worked on.
Projects
None yet
Development

No branches or pull requests

2 participants