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

Wrong result when IntegralNumber Payload evaluated by FloatingPointNumber Rule #47

Open
wapkch opened this issue Apr 19, 2023 · 1 comment
Assignees
Labels

Comments

@wapkch
Copy link

wapkch commented Apr 19, 2023

Describe the bug
Assuming we have the following Rule and Payload:

Rule

{
          "type": "between",
          "path": "$.amount",
          "lowerBound": -5.9,
          "includeLowerBound": true,
          "upperBound": -0.9,
          "includeUpperBound": true
 },

Paylod

   {
      "amount": "0"
   }

The problem is that the payload will be evaluated to false by the rule because of the evaluate method in class io.appform.jsonrules.expressions.numeric.BetweenExpression:

@Override
    protected boolean evaluate(ExpressionEvaluationContext context, String path, JsonNode evaluatedNode) {
        if (null == evaluatedNode || !evaluatedNode.isNumber()) {
            return false;
        }
        boolean finalResult = false;
        if (evaluatedNode.isIntegralNumber()) {
            finalResult = includeLowerBound ? evaluatedNode.asLong() >= lowerBound.longValue()
                    : evaluatedNode.asLong() > lowerBound.longValue();
            finalResult &= includeUpperBound ? evaluatedNode.asLong() <= upperBound.longValue()
                    : evaluatedNode.asLong() < upperBound.longValue();
        } else if (evaluatedNode.isFloatingPointNumber()) {
            finalResult = includeLowerBound ? evaluatedNode.doubleValue() >= lowerBound.doubleValue()
                    : evaluatedNode.doubleValue() > lowerBound.doubleValue();
            finalResult &= includeUpperBound ? evaluatedNode.doubleValue() <= upperBound.doubleValue()
                    : evaluatedNode.doubleValue() < upperBound.doubleValue();
        }
        return finalResult;
    }

If the param in payload is 0 which is a IntegralNumber, then lowerBound and upperBound will be converted to long value even if they are defined as FloatingPointNumber in rule.

@santanusinha
Copy link
Owner

Thanks for the report @wapkch .. we shall provide a fix for this.

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

No branches or pull requests

3 participants