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

Fix for incorrectly uppercased keys #2618

Merged
merged 1 commit into from
May 25, 2018
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
8 changes: 7 additions & 1 deletion src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ export function newTargeting(auctionManager) {
// setKeywords supports string and array as value
if (utils.isStr(astTargeting[targetId][key]) || utils.isArray(astTargeting[targetId][key])) {
let keywordsObj = {};
keywordsObj[key.toUpperCase()] = astTargeting[targetId][key];
let regex = /pt[0-9]/;
if (key.search(regex) < 0) {
keywordsObj[key.toUpperCase()] = astTargeting[targetId][key];
} else {
// pt${n} keys should not be uppercased
keywordsObj[key] = astTargeting[targetId][key];
}
window.apntag.setKeywords(targetId, keywordsObj);
}
})
Expand Down
14 changes: 11 additions & 3 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,10 @@ describe('Unit: Prebid Module', function () {
resetAuction();
auctionManagerInstance = newAuctionManager();
sinon.stub(auctionManagerInstance, 'getBidsReceived').callsFake(function() {
return [getBidResponses()[1]];
let bidResponse = getBidResponses()[1];
// add a pt0 value for special case.
bidResponse.adserverTargeting.pt0 = 'someVal';
return [bidResponse];
});
sinon.stub(auctionManagerInstance, 'getAdUnitCodes').callsFake(function() {
return ['/19968336/header-bid-tag-0'];
Expand All @@ -1832,10 +1835,15 @@ describe('Unit: Prebid Module', function () {

var expectedAdserverTargeting = bids[0].adserverTargeting;
var newAdserverTargeting = {};
let regex = /pt[0-9]/;

for (var key in expectedAdserverTargeting) {
newAdserverTargeting[key.toUpperCase()] = expectedAdserverTargeting[key];
if (key.search(regex) < 0) {
newAdserverTargeting[key.toUpperCase()] = expectedAdserverTargeting[key];
} else {
newAdserverTargeting[key] = expectedAdserverTargeting[key];
}
}

targeting.setTargetingForAst();
expect(newAdserverTargeting).to.deep.equal(window.apntag.tags[adUnitCode].keywords);
});
Expand Down