Skip to content

fix: number.multiple() with decimal ref base wrongly rejects valid values - #3128

Open
chatman-media wants to merge 1 commit into
hapijs:masterfrom
chatman-media:fix/multiple-decimal-ref-base
Open

fix: number.multiple() with decimal ref base wrongly rejects valid values#3128
chatman-media wants to merge 1 commit into
hapijs:masterfrom
chatman-media:fix/multiple-decimal-ref-base

Conversation

@chatman-media

@chatman-media chatman-media commented Jul 2, 2026

Copy link
Copy Markdown

When the base of .multiple() is a ref instead of a literal, baseDecimalPlace is precomputed as null at schema-build time (only literal numbers get their decimal places counted upfront). At validate time that null gets compared against the value's decimal place count with >, and JS happily coerces null to 0 there, so any value with a fractional part gets rejected outright whenever the resolved ref turns out to be a decimal — even for legit multiples like base 0.5 / value 1.5.

You can see the asymmetry pretty clearly: Joi.number().multiple(0.5).validate(1.5) passes, but Joi.number().multiple(Joi.ref('base')).validate({base: 0.5, value: 1.5}) (wrapped in an object schema) fails with "must be a multiple of ref:base". Fix just recomputes decimal place/factor from the resolved value when the build-time one is null. Added a test alongside the existing ref-based multiple tests, which previously only covered integer bases.

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 this pull request may close these issues.

1 participant