Skip to content

Fix NaN handling in getResponseAdForSlot - #1243

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/response-ad-slot-nan-handling
Open

Fix NaN handling in getResponseAdForSlot#1243
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/response-ad-slot-nan-handling

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Fix NaN handling in the getResponseAdForSlot function in common/src/util/lazy-response-ads.ts.

Bug Description

The function didn't validate that slotIndex is a finite number. If slotIndex was NaN or Infinity, Math.floor(NaN) would return NaN, causing Math.max(0, NaN) to return NaN, and NaN % ads.length to return NaN.

Fix

Added Number.isFinite() check 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 validation

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

The function didn't validate that slotIndex is a finite number. If slotIndex
was NaN or Infinity, Math.floor(NaN) would return NaN, causing Math.max(0, NaN)
to return NaN, and NaN % ads.length to return NaN.

Added Number.isFinite() check to default to 0 for invalid numbers.
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