Fix NaN handling in responseAdSlotCount with tests - #1409
pavankumar-vh wants to merge 1 commit into
Conversation
The function didn't validate that nodeCount is a finite number. If nodeCount was NaN or Infinity, Math.floor((NaN - firstAdAfterNodes - 1) / step) would return NaN, causing incorrect results. Added Number.isFinite() checks for nodeCount, step, and firstAdAfterNodes to default to safe values for invalid numbers. Added comprehensive test coverage for: - Valid nodeCount values - NaN, Infinity, and negative nodeCount handling - Custom step and firstAdAfterNodes parameters - Empty and valid adCount cases All 11 tests pass.
|
Good catch: A few things worth tightening before this is ready to port:
Overall the logic is sound and the tests are genuinely useful regression coverage. Clean up the formatting and firm up the justification and this is portable. |
Overview
Fix NaN handling in the
responseAdSlotCountfunction incommon/src/util/response-ad-positions.ts.Bug Description
The function didn't validate that nodeCount is a finite number. If nodeCount was NaN or Infinity,
Math.floor((NaN - firstAdAfterNodes - 1) / step)would return NaN, causing incorrect results.Fix
Added
Number.isFinite()checks for nodeCount, step, and firstAdAfterNodes to default to safe values for invalid numbers.Testing
Added comprehensive test coverage for:
All 11 tests pass.
Files Changed
common/src/util/response-ad-positions.ts- Added NaN validationcommon/src/util/__tests__/response-ad-positions.test.ts- Added test coverageScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.