Skip to content

Commit

Permalink
Use BigDecimal for multiple_of check
Browse files Browse the repository at this point in the history
Fixes overflow error 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'
```
  • Loading branch information
davishmcclurg committed Oct 17, 2021
1 parent b6c9d38 commit f2d1c3c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/json_schemer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'base64'
require 'bigdecimal'
require 'ipaddr'
require 'json'
require 'net/http'
Expand Down
3 changes: 1 addition & 2 deletions lib/json_schemer/schema/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ def validate_numeric(instance, &block)
validate_exclusive_minimum(instance, exclusive_minimum, minimum, &block) if exclusive_minimum

if multiple_of
quotient = data / multiple_of.to_f
yield error(instance, 'multipleOf') unless quotient.floor == quotient
yield error(instance, 'multipleOf') unless BigDecimal(data.to_s).modulo(multiple_of).zero?
end
end

Expand Down

0 comments on commit f2d1c3c

Please sign in to comment.