Skip to content

Commit

Permalink
Fix double encoded targeting string for Yieldlab adapter (#5522)
Browse files Browse the repository at this point in the history
* Fix double encoded targeting string in query string

Values in the targeting string can include comma (',') and we do not want to double encode those as we will encode again when we build the querystring with createQueryString().

* Include check for double encoding in targeting unit test
  • Loading branch information
mirkorean authored Jul 23, 2020
1 parent 7535132 commit 6e71525
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
19 changes: 18 additions & 1 deletion modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const spec = {
utils._each(validBidRequests, function (bid) {
adslotIds.push(bid.params.adslotId)
if (bid.params.targeting) {
query.t = createQueryString(bid.params.targeting)
query.t = createTargetingString(bid.params.targeting)
}
if (bid.userIdAsEids && Array.isArray(bid.userIdAsEids)) {
query.ids = createUserIdString(bid.userIdAsEids)
Expand Down Expand Up @@ -204,6 +204,23 @@ function createQueryString (obj) {
return str.join('&')
}

/**
* Creates an unencoded targeting string out of an object with key-values
* @param {Object} obj
* @returns {String}
*/
function createTargetingString (obj) {
let str = []
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
let key = p
let val = obj[p]
str.push(key + '=' + val)
}
}
return str.join('&')
}

/**
* Handles an outstream response after the library is loaded
* @param {Object} bid
Expand Down
7 changes: 4 additions & 3 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const REQUEST = {
'adSize': '728x90',
'targeting': {
'key1': 'value1',
'key2': 'value2'
'key2': 'value2',
'notDoubleEncoded': 'value3,value4'
},
'customParams': {
'extraParam': true,
Expand Down Expand Up @@ -84,8 +85,8 @@ describe('yieldlabBidAdapter', function () {
expect(request.validBidRequests).to.eql([REQUEST])
})

it('passes targeting to bid request', function () {
expect(request.url).to.include('t=key1%3Dvalue1%26key2%3Dvalue2')
it('passes single-encoded targeting to bid request', function () {
expect(request.url).to.include('t=key1%3Dvalue1%26key2%3Dvalue2%26notDoubleEncoded%3Dvalue3%2Cvalue4')
})

it('passes userids to bid request', function () {
Expand Down

0 comments on commit 6e71525

Please sign in to comment.