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

Number validation with multipleOf: 0.01 is giving false positive errors #100

Closed
legendetm opened this issue Mar 25, 2022 · 1 comment · Fixed by #102
Closed

Number validation with multipleOf: 0.01 is giving false positive errors #100

legendetm opened this issue Mar 25, 2022 · 1 comment · Fixed by #102

Comments

@legendetm
Copy link

Code example

schema = <<~JSON
  {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
      "amount": {
        "type": "number",
        "multipleOf": 0.01
      }
    },
    "additionalProperties": false
  }
JSON
JSONSchemer.schema(schema).valid?({ "amount" => 8.61 }) #=> false

I expect the JSON data to be valid.

The problematic part of the the code is validate_numeric because it treats the numbers as floats.

davishmcclurg added a commit that referenced this issue Apr 1, 2022
Floats aren't accurate enough here.

Fixes: #100

Also addresses overflow exposed by: json-schema-org/JSON-Schema-Test-Suite#438

```
FloatDomainError: Infinity
    /Users/dharsha/repos/json_schemer/lib/json_schemer/schema/base.rb:367:in `floor'
    /Users/dharsha/repos/json_schemer/lib/json_schemer/schema/base.rb:367:in `validate_numeric'
    /Users/dharsha/repos/json_schemer/lib/json_schemer/schema/base.rb:378:in `validate_number'
    /Users/dharsha/repos/json_schemer/lib/json_schemer/schema/base.rb:277:in `validate_type'
    /Users/dharsha/repos/json_schemer/lib/json_schemer/schema/base.rb:198:in `validate_instance'
```
@davishmcclurg
Copy link
Owner

Thanks for the issue @legendetm! Should be fixed in 0.2.20

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

Successfully merging a pull request may close this issue.

2 participants