Skip to content

Commit

Permalink
Check for multipleOf overflow
Browse files Browse the repository at this point in the history
The spec says that instances are valid if "dividing by this value results in an integer".

This allows integers to be invalid for `multipleOf: 0.5` if float division overflows to infinity (a non-integer); alternatively implementations may choose to implement logic which defines all integers as multiples of 0.5.  Either way, however, implementations must not raise an error due to the overflow of a legal value against a legal schema.
  • Loading branch information
Zac-HD committed Oct 3, 2020
1 parent c12b0db commit a2a52b1
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/draft2019-09/multipleOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,16 @@
"valid": false
}
]
},
{
"description": "invalid instance which must not raise an overflow error when float division = inf",
"schema": {"type": "integer", "multipleOf": 0.123456789},
"tests": [
{
"description": "This should always be invalid, but naive implementations may raise an overflow error",
"data": 1e308,
"valid": false
}
]
}
]
13 changes: 13 additions & 0 deletions tests/draft2019-09/optional/float-overflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity",
"schema": {"type": "integer", "multipleOf": 0.5},
"tests": [
{
"description": "The spec allows this to be valid OR invalid depending on your overflow handling.",
"data": 1e308,
"valid": true
}
]
}
]
11 changes: 11 additions & 0 deletions tests/draft4/multipleOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,16 @@
"valid": false
}
]
},
{
"description": "invalid instance which must not raise an overflow error when float division = inf",
"schema": {"type": "integer", "multipleOf": 0.123456789},
"tests": [
{
"description": "This should always be invalid, but naive implementations may raise an overflow error",
"data": 1e308,
"valid": false
}
]
}
]
13 changes: 13 additions & 0 deletions tests/draft4/optional/float-overflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity",
"schema": {"type": "integer", "multipleOf": 0.5},
"tests": [
{
"description": "The spec allows this to be valid OR invalid depending on your overflow handling.",
"data": 1e308,
"valid": true
}
]
}
]
11 changes: 11 additions & 0 deletions tests/draft6/multipleOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,16 @@
"valid": false
}
]
},
{
"description": "invalid instance which must not raise an overflow error when float division = inf",
"schema": {"type": "integer", "multipleOf": 0.123456789},
"tests": [
{
"description": "This should always be invalid, but naive implementations may raise an overflow error",
"data": 1e308,
"valid": false
}
]
}
]
13 changes: 13 additions & 0 deletions tests/draft6/optional/float-overflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity",
"schema": {"type": "integer", "multipleOf": 0.5},
"tests": [
{
"description": "The spec allows this to be valid OR invalid depending on your overflow handling.",
"data": 1e308,
"valid": true
}
]
}
]
11 changes: 11 additions & 0 deletions tests/draft7/multipleOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,16 @@
"valid": false
}
]
},
{
"description": "invalid instance which must not raise an overflow error when float division = inf",
"schema": {"type": "integer", "multipleOf": 0.123456789},
"tests": [
{
"description": "This should always be invalid, but naive implementations may raise an overflow error",
"data": 1e308,
"valid": false
}
]
}
]
13 changes: 13 additions & 0 deletions tests/draft7/optional/float-overflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity",
"schema": {"type": "integer", "multipleOf": 0.5},
"tests": [
{
"description": "The spec allows this to be valid OR invalid depending on your overflow handling.",
"data": 1e308,
"valid": true
}
]
}
]

0 comments on commit a2a52b1

Please sign in to comment.