Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prebid core: do not enforce valid size in bid responses #9138

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
})
});