Skip to content

Fixes #2291 - user cust_params data lost with url option for dfpAdServerVideo module #2308

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

Merged
merged 1 commit into from
Apr 3, 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
5 changes: 3 additions & 2 deletions modules/dfpAdServerVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function buildDfpVideoUrl(options) {
if (options.url) {
// when both `url` and `params` are given, parsed url will be overwriten
// with any matching param components
urlComponents = parse(options.url);
urlComponents = parse(options.url, {noDecodeWholeURL: true});

if (isEmpty(options.params)) {
return buildUrlFromAdserverUrlComponents(urlComponents, bid);
Expand Down Expand Up @@ -126,7 +126,8 @@ function buildUrlFromAdserverUrlComponents(components, bid) {
const customParams = Object.assign({},
adserverTargeting,
);
components.search.cust_params = encodeURIComponent(formatQS(customParams));
const encodedCustomParams = encodeURIComponent(formatQS(customParams));
components.search.cust_params = (components.search.cust_params) ? components.search.cust_params + '%26' + encodedCustomParams : encodedCustomParams;

return buildUrl(components);
}
Expand Down
20 changes: 20 additions & 0 deletions test/spec/modules/dfpAdServerVideo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ describe('The DFP video support module', () => {
expect(customParams).to.have.property('my_targeting', 'foo');
});

it('should merge the user-provided cust-params with the default ones when using url object', () => {
const bidCopy = Object.assign({ }, bid);
bidCopy.adserverTargeting = {
hb_adid: 'ad_id',
};

const url = parse(buildDfpVideoUrl({
adUnit: adUnit,
bid: bidCopy,
url: 'https://video.adserver.example/ads?sz=640x480&iu=/123/aduniturl&impl=s&cust_params=section%3dblog%26mykey%3dmyvalue'
}));

const queryObject = parseQS(url.query);
const customParams = parseQS('?' + decodeURIComponent(queryObject.cust_params));

expect(customParams).to.have.property('hb_adid', 'ad_id');
expect(customParams).to.have.property('section', 'blog');
expect(customParams).to.have.property('mykey', 'myvalue');
});

it('should not overwrite an existing description_url for object input and cache disabled', () => {
const bidCopy = Object.assign({}, bid);
bidCopy.vastUrl = 'vastUrl.example';
Expand Down