Skip to content

Commit 6363197

Browse files
nanekmkendall07
authored andcommitted
Only set native targeting if value exists. (#3225)
1 parent 5743e2b commit 6363197

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export function fireNativeTrackers(message, adObject) {
147147
}
148148

149149
/**
150-
* Gets native targeting key-value paris
150+
* Gets native targeting key-value pairs
151151
* @param {Object} bid
152152
* @return {Object} targeting
153153
*/
@@ -163,7 +163,7 @@ export function getNativeTargeting(bid) {
163163
value = value.url;
164164
}
165165

166-
if (key) {
166+
if (key && value) {
167167
keyValues[key] = value;
168168
}
169169
});

test/spec/native_spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ const bid = {
1616
}
1717
};
1818

19+
const bidWithUndefinedFields = {
20+
native: {
21+
title: 'Native Creative',
22+
body: undefined,
23+
cta: undefined,
24+
sponsoredBy: 'AppNexus',
25+
clickUrl: 'https://www.link.example',
26+
clickTrackers: ['https://tracker.example'],
27+
impressionTrackers: ['https://impression.example'],
28+
javascriptTrackers: '<script src=\"http://www.foobar.js\"></script>'
29+
}
30+
};
31+
1932
describe('native.js', function () {
2033
let triggerPixelStub;
2134
let insertHtmlIntoIframeStub;
@@ -37,6 +50,16 @@ describe('native.js', function () {
3750
expect(targeting[CONSTANTS.NATIVE_KEYS.clickUrl]).to.equal(bid.native.clickUrl);
3851
});
3952

53+
it('should only include native targeting keys with values', function () {
54+
const targeting = getNativeTargeting(bidWithUndefinedFields);
55+
56+
expect(Object.keys(targeting)).to.deep.equal([
57+
CONSTANTS.NATIVE_KEYS.title,
58+
CONSTANTS.NATIVE_KEYS.sponsoredBy,
59+
CONSTANTS.NATIVE_KEYS.clickUrl
60+
]);
61+
});
62+
4063
it('fires impression trackers', function () {
4164
fireNativeTrackers({}, bid);
4265
sinon.assert.calledOnce(triggerPixelStub);

0 commit comments

Comments
 (0)