Skip to content

Commit

Permalink
Prebid core: do not enforce valid size in bid responses (#9138)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Oct 21, 2022
1 parent c0260f2 commit df2418d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 11 additions & 9 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,22 +545,24 @@ export function getIabSubCategory(bidderCode, category) {

// check that the bid has a width and height set
function validBidSize(adUnitCode, bid, {index = auctionManager.index} = {}) {
const bidRequest = index.getBidRequest(bid);
const mediaTypes = index.getMediaTypes(bid);

const sizes = (bidRequest && bidRequest.sizes) || (mediaTypes && mediaTypes.banner && mediaTypes.banner.sizes);
const parsedSizes = parseSizesInput(sizes).map(sz => sz.split('x').map(n => parseInt(n, 10)));

if ((bid.width || parseInt(bid.width, 10) === 0) && (bid.height || parseInt(bid.height, 10) === 0)) {
bid.width = parseInt(bid.width, 10);
bid.height = parseInt(bid.height, 10);
return parsedSizes.length === 0 || parsedSizes.some(([w, h]) => bid.width === w && bid.height === h);
return true;
}

const bidRequest = index.getBidRequest(bid);
const mediaTypes = index.getMediaTypes(bid);

const sizes = (bidRequest && bidRequest.sizes) || (mediaTypes && mediaTypes.banner && mediaTypes.banner.sizes);
const parsedSizes = parseSizesInput(sizes);

// if a banner impression has one valid size, we assign that size to any bid
// response that does not explicitly set width or height
if (parsedSizes.length === 1) {
([bid.width, bid.height] = parsedSizes[0]);
const [ width, height ] = parsedSizes[0].split('x');
bid.width = parseInt(width, 10);
bid.height = parseInt(height, 10);
return true;
}

Expand Down Expand Up @@ -602,7 +604,7 @@ export function isValid(adUnitCode, bid, {index = auctionManager.index} = {}) {
return false;
}
if (bid.mediaType === 'banner' && !validBidSize(adUnitCode, bid, {index})) {
logError(errorMessage(`Banner bids require a width and height that match one of the requested sizes`));
logError(errorMessage(`Banner bids require a width and height`));
return false;
}

Expand Down
4 changes: 0 additions & 4 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,9 +1434,5 @@ describe('bid response isValid', () => {
it('should succeed when response has a size that was in request', () => {
expect(checkValid(mkResponse(3, 4))).to.be.true;
});

it('should fail when response has a size that was not in request', () => {
expect(checkValid(mkResponse(10, 11))).to.be.false;
});
})
});

0 comments on commit df2418d

Please sign in to comment.