Skip to content

Commit

Permalink
DFP Ad Server Video: bugfix - encode description url (#10575)
Browse files Browse the repository at this point in the history
* encodes page in description url

* adds test

* typo
  • Loading branch information
karimMourra committed Oct 5, 2023
1 parent 2f6089e commit ee9ad4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions modules/dfpAdServerVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ export function buildAdpodVideoUrl({code, params, callback} = {}) {
*/
function buildUrlFromAdserverUrlComponents(components, bid, options) {
const descriptionUrl = getDescriptionUrl(bid, components, 'search');
if (descriptionUrl) { components.search.description_url = descriptionUrl; }
if (descriptionUrl) {
components.search.description_url = descriptionUrl;
}

components.search.cust_params = getCustParams(bid, options, components.search.cust_params);
return buildUrl(components);
Expand All @@ -264,7 +266,7 @@ function buildUrlFromAdserverUrlComponents(components, bid, options) {
* @return {string | undefined} The encoded vast url if it exists, or undefined
*/
function getDescriptionUrl(bid, components, prop) {
return deepAccess(components, `${prop}.description_url`) || dep.ri().page;
return deepAccess(components, `${prop}.description_url`) || encodeURIComponent(dep.ri().page);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions test/spec/modules/dfpAdServerVideo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ describe('The DFP video support module', function () {
}, options)));
const prm = utils.parseQS(url.query);
expect(prm.description_url).to.eql('example.com');
})
})
});

it('should use a URI encoded page location as default for description_url', () => {
sandbox.stub(dep, 'ri').callsFake(() => ({page: 'https://example.com?iu=/99999999/news&cust_params=current_hour%3D12%26newscat%3Dtravel&pbjs_debug=true'}));
const url = parse(buildDfpVideoUrl(Object.assign({
adUnit: adUnit,
bid: bid,
}, options)));
const prm = utils.parseQS(url.query);
expect(prm.description_url).to.eql('https%3A%2F%2Fexample.com%3Fiu%3D%2F99999999%2Fnews%26cust_params%3Dcurrent_hour%253D12%2526newscat%253Dtravel%26pbjs_debug%3Dtrue');
});
});
})

it('should make a legal request URL when given the required params', function () {
Expand Down

0 comments on commit ee9ad4c

Please sign in to comment.