Skip to content

Prebid core: fix bug with native adUnits generating invalid PBS requests #8977

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

Merged
merged 1 commit into from
Sep 9, 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
2 changes: 2 additions & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@
"MAIN": 3
},
"NATIVE_KEYS_THAT_ARE_NOT_ASSETS": [
"privacyLink",
"clickUrl",
"sendTargetingKeys",
"adTemplate",
"rendererUrl",
Expand Down
7 changes: 5 additions & 2 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const SUPPORTED_TYPES = {
image: IMAGE
};

const { NATIVE_ASSET_TYPES, NATIVE_IMAGE_TYPES, PREBID_NATIVE_DATA_KEYS_TO_ORTB, NATIVE_KEYS_THAT_ARE_NOT_ASSETS } = CONSTANTS;
const { NATIVE_ASSET_TYPES, NATIVE_IMAGE_TYPES, PREBID_NATIVE_DATA_KEYS_TO_ORTB, NATIVE_KEYS_THAT_ARE_NOT_ASSETS, NATIVE_KEYS } = CONSTANTS;

// inverse native maps useful for converting to legacy
const PREBID_NATIVE_DATA_KEYS_TO_ORTB_INVERSE = inverse(PREBID_NATIVE_DATA_KEYS_TO_ORTB);
Expand Down Expand Up @@ -488,6 +488,10 @@ export function toOrtbNativeRequest(legacyNativeAssets) {
for (let key in legacyNativeAssets) {
// skip conversion for non-asset keys
if (NATIVE_KEYS_THAT_ARE_NOT_ASSETS.includes(key)) continue;
if (!NATIVE_KEYS.hasOwnProperty(key)) {
logError(`Unrecognized native asset code: ${key}. Asset will be ignored.`);
continue;
}

const asset = legacyNativeAssets[key];
let required = 0;
Expand Down Expand Up @@ -560,7 +564,6 @@ export function toOrtbNativeRequest(legacyNativeAssets) {
// in `ext` case, required field is not needed
delete ortbAsset.required;
}

ortb.assets.push(ortbAsset);
}
return ortb;
Expand Down
11 changes: 11 additions & 0 deletions test/spec/native_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,17 @@ describe('validate native', function () {
});
});

['bogusKey', 'clickUrl', 'privacyLink'].forEach(nativeKey => {
it(`should not generate an empty asset for key ${nativeKey}`, () => {
const ortbReq = toOrtbNativeRequest({
[nativeKey]: {
required: true
}
});
expect(ortbReq.assets.length).to.equal(0);
});
})

it('should convert from ortb to old-style native request', () => {
const openRTBRequest = {
'ver': '1.2',
Expand Down