Skip to content

Commit c5ba4ba

Browse files
committed
Check for multipleOf overflow
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.
1 parent c12b0db commit c5ba4ba

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-0
lines changed

tests/draft2019-09/multipleOf.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@
5656
"valid": false
5757
}
5858
]
59+
},
60+
{
61+
"description": "invalid instance should not raise error when float division = inf",
62+
"schema": {"type": "integer", "multipleOf": 0.123456789},
63+
"tests": [
64+
{
65+
"description": "always invalid, but naive implementations may raise an overflow error",
66+
"data": 1e308,
67+
"valid": false
68+
}
69+
]
5970
}
6071
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"description": "all integers are multiples of 0.5, if overflow is handled",
4+
"schema": {"type": "integer", "multipleOf": 0.5},
5+
"tests": [
6+
{
7+
"description": "valid if optional overflow handling is implemented",
8+
"data": 1e308,
9+
"valid": true
10+
}
11+
]
12+
}
13+
]

tests/draft4/multipleOf.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@
5656
"valid": false
5757
}
5858
]
59+
},
60+
{
61+
"description": "invalid instance should not raise error when float division = inf",
62+
"schema": {"type": "integer", "multipleOf": 0.123456789},
63+
"tests": [
64+
{
65+
"description": "always invalid, but naive implementations may raise an overflow error",
66+
"data": 1e308,
67+
"valid": false
68+
}
69+
]
5970
}
6071
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"description": "all integers are multiples of 0.5, if overflow is handled",
4+
"schema": {"type": "integer", "multipleOf": 0.5},
5+
"tests": [
6+
{
7+
"description": "valid if optional overflow handling is implemented",
8+
"data": 1e308,
9+
"valid": true
10+
}
11+
]
12+
}
13+
]

tests/draft6/multipleOf.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@
5656
"valid": false
5757
}
5858
]
59+
},
60+
{
61+
"description": "invalid instance should not raise error when float division = inf",
62+
"schema": {"type": "integer", "multipleOf": 0.123456789},
63+
"tests": [
64+
{
65+
"description": "always invalid, but naive implementations may raise an overflow error",
66+
"data": 1e308,
67+
"valid": false
68+
}
69+
]
5970
}
6071
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"description": "all integers are multiples of 0.5, if overflow is handled",
4+
"schema": {"type": "integer", "multipleOf": 0.5},
5+
"tests": [
6+
{
7+
"description": "valid if optional overflow handling is implemented",
8+
"data": 1e308,
9+
"valid": true
10+
}
11+
]
12+
}
13+
]

tests/draft7/multipleOf.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@
5656
"valid": false
5757
}
5858
]
59+
},
60+
{
61+
"description": "invalid instance should not raise error when float division = inf",
62+
"schema": {"type": "integer", "multipleOf": 0.123456789},
63+
"tests": [
64+
{
65+
"description": "always invalid, but naive implementations may raise an overflow error",
66+
"data": 1e308,
67+
"valid": false
68+
}
69+
]
5970
}
6071
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"description": "all integers are multiples of 0.5, if overflow is handled",
4+
"schema": {"type": "integer", "multipleOf": 0.5},
5+
"tests": [
6+
{
7+
"description": "valid if optional overflow handling is implemented",
8+
"data": 1e308,
9+
"valid": true
10+
}
11+
]
12+
}
13+
]

0 commit comments

Comments
 (0)