Skip to content

Commit ff90bcf

Browse files
committed
Prebid core: fix bug with native adUnits generating invalid PBS requests
1 parent 918ffb9 commit ff90bcf

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/constants.json

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152
"MAIN": 3
153153
},
154154
"NATIVE_KEYS_THAT_ARE_NOT_ASSETS": [
155+
"privacyLink",
156+
"clickUrl",
155157
"sendTargetingKeys",
156158
"adTemplate",
157159
"rendererUrl",

src/native.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const SUPPORTED_TYPES = {
8080
image: IMAGE
8181
};
8282

83-
const { NATIVE_ASSET_TYPES, NATIVE_IMAGE_TYPES, PREBID_NATIVE_DATA_KEYS_TO_ORTB, NATIVE_KEYS_THAT_ARE_NOT_ASSETS } = CONSTANTS;
83+
const { NATIVE_ASSET_TYPES, NATIVE_IMAGE_TYPES, PREBID_NATIVE_DATA_KEYS_TO_ORTB, NATIVE_KEYS_THAT_ARE_NOT_ASSETS, NATIVE_KEYS } = CONSTANTS;
8484

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

492496
const asset = legacyNativeAssets[key];
493497
let required = 0;
@@ -560,7 +564,6 @@ export function toOrtbNativeRequest(legacyNativeAssets) {
560564
// in `ext` case, required field is not needed
561565
delete ortbAsset.required;
562566
}
563-
564567
ortb.assets.push(ortbAsset);
565568
}
566569
return ortb;

test/spec/native_spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,17 @@ describe('validate native', function () {
877877
});
878878
});
879879

880+
['bogusKey', 'clickUrl', 'privacyLink'].forEach(nativeKey => {
881+
it(`should not generate an empty asset for key ${nativeKey}`, () => {
882+
const ortbReq = toOrtbNativeRequest({
883+
[nativeKey]: {
884+
required: true
885+
}
886+
});
887+
expect(ortbReq.assets.length).to.equal(0);
888+
});
889+
})
890+
880891
it('should convert from ortb to old-style native request', () => {
881892
const openRTBRequest = {
882893
'ver': '1.2',

0 commit comments

Comments
 (0)