Skip to content

Commit ae71725

Browse files
committed
fix: ensure we don't overflow in isMultipleOf() check
Refs: json-schema-org/JSON-Schema-Test-Suite#534 (comment)
1 parent cd58073 commit ae71725

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/scope-functions.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ const stringLength = (string) =>
77

88
// A isMultipleOf B: shortest decimal denoted as A % shortest decimal denoted as B === 0
99
// Optimized, coherence checks and precomputation are outside of this method
10+
// If we get an Infinity when we multiply by the factor (which is always a power of 10), we just undo that instead of always returning false
1011
const isMultipleOf = (value, divisor, factor, factorMultiple) => {
1112
if (value % divisor === 0) return true
12-
const multiple = value * factor
13+
let multiple = value * factor
14+
if (multiple === Infinity || multiple === -Infinity) multiple = value
1315
if (multiple % factorMultiple === 0) return true
1416
const normal = Math.floor(multiple + 0.5)
1517
return normal / factor === value && normal % factorMultiple === 0

0 commit comments

Comments
 (0)