Fix NaN/Infinity handling in responseAdDisplayCount - #1237
Conversation
The function used Math.floor() without checking if the input was a valid number. If params.eligibleCount or params.poolSize was NaN or Infinity, Math.floor() would return NaN, and Math.max(0, NaN) would return NaN, causing incorrect results. Added Number.isFinite() checks to default to 0 for invalid numbers.
|
Thanks for the contribution. The change itself is small and correct in isolation: guarding against A few things that would make this port-ready:
Add a small test file exercising these edge cases and this becomes an easy merge. |
Overview
Fix NaN/Infinity handling in the
responseAdDisplayCountfunction incommon/src/util/lazy-response-ads.ts.Bug Description
The function used
Math.floor()without checking if the input was a valid number. Ifparams.eligibleCountorparams.poolSizewas NaN or Infinity,Math.floor()would return NaN, andMath.max(0, NaN)would return NaN, causing incorrect results.Fix
Added
Number.isFinite()checks to default to 0 for invalid numbers.Testing
No existing tests for this function, but the fix prevents incorrect behavior with invalid inputs.
Files Changed
common/src/util/lazy-response-ads.ts- Added NaN/Infinity validationScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.