Skip to content

Commit

Permalink
Fix for incorrectly uppercased keys (prebid#2618)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkendall07 authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent 83864a5 commit 5e2f17f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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 @@ -1813,7 +1813,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 @@ -1833,10 +1836,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

0 comments on commit 5e2f17f

Please sign in to comment.