Fix NaN/Infinity handling in responseAdDisplayCount with tests - #1270
Fix NaN/Infinity handling in responseAdDisplayCount with tests#1270pavankumar-vh wants to merge 1 commit into
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. Also added comprehensive test coverage: - Valid inputs (eligibleCount, poolSize) - NaN handling for both parameters - Infinity handling for both parameters - Negative inputs - Fractional inputs (flooring behavior) All 8 tests pass.
|
Thanks for the clean, focused patch. The fix itself is correct: One thing worth clarifying in the PR description for the maintainer's benefit: where do Minor style nit: consider running this through the repo's formatter (some lines exceed the project's typical line-length conventions, e.g. the Overall this is the right shape for a common/ contribution: small, scoped, tested, and doesn't touch anything out of bounds. |
Overview
Fix NaN/Infinity handling in the
responseAdDisplayCountfunction incommon/src/util/lazy-response-ads.tswith comprehensive test coverage.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
Added comprehensive test coverage with 8 test cases:
All 8 tests pass.
Files Changed
common/src/util/lazy-response-ads.ts- Added NaN/Infinity validationcommon/src/util/__tests__/lazy-response-ads.test.ts- New test file with 8 test casesScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.