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

Eplanning Bid Adapter : cut url when url size greater than 255 #9606

Merged
merged 2 commits into from
Mar 1, 2023
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
16 changes: 14 additions & 2 deletions modules/eplanningBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const VAST_INSTREAM = 1;
const VAST_OUTSTREAM = 2;
const VAST_VERSION_DEFAULT = 3;
const DEFAULT_SIZE_VAST = '640x480';
const MAX_LEN_URL = 255;

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -60,7 +61,7 @@ export const spec = {
params = {
rnd: rnd,
e: spaces.str,
ur: pageUrl || FILE,
ur: cutUrl(pageUrl || FILE),
pbv: '$prebid.version$',
ncb: '1',
vs: spaces.vs
Expand All @@ -70,7 +71,7 @@ export const spec = {
}

if (referrerUrl) {
params.fr = referrerUrl;
params.fr = cutUrl(referrerUrl);
}

if (bidderRequest && bidderRequest.gdprConsent) {
Expand Down Expand Up @@ -491,6 +492,17 @@ function visibilityHandler(obj) {
}
}

function cutUrl (url) {
if (url.length > MAX_LEN_URL) {
url = url.split('?')[0];
if (url.length > MAX_LEN_URL) {
url = url.slice(0, MAX_LEN_URL);
}
}

return url;
}

function registerAuction(storageID) {
let value;
try {
Expand Down
35 changes: 35 additions & 0 deletions test/spec/modules/eplanningBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,46 @@ describe('E-Planning Adapter', function () {
expect(ur).to.equal(bidderRequest.refererInfo.page);
});

it('should return ur parameter without params query string when current window url length is greater than 255', function () {
let bidderRequestParams = bidderRequest;

bidderRequestParams.refererInfo.page = refererUrl + '?param=' + 'x'.repeat(255);
const ur = spec.buildRequests(bidRequests, bidderRequest).data.ur;
expect(ur).to.equal(refererUrl);
});

it('should return ur parameter with a length of 255 when url length is greater than 255', function () {
let bidderRequestParams = bidderRequest;
let url_255_characters = 'https://localhost/abc' + '/subse'.repeat(39);
let refererUrl = url_255_characters + '/ext'.repeat(5) + '?param=' + 'x'.repeat(15);

bidderRequestParams.refererInfo.page = refererUrl;
const ur = spec.buildRequests(bidRequests, bidderRequest).data.ur;
expect(ur).to.equal(url_255_characters);
});

it('should return fr parameter when there is a referrer', function () {
const request = spec.buildRequests(bidRequests, bidderRequest);
const dataRequest = request.data;
expect(dataRequest.fr).to.equal(refererUrl);
});
it('should return fr parameter without params query string when ref length is greater than 255', function () {
let bidderRequestParams = bidderRequest;

bidderRequestParams.refererInfo.ref = refererUrl + '?param=' + 'x'.repeat(255);
const fr = spec.buildRequests(bidRequests, bidderRequest).data.fr;
expect(fr).to.equal(refererUrl);
});

it('should return fr parameter with a length of 255 when url length is greater than 255', function () {
let bidderRequestParams = bidderRequest;
let url_255_characters = 'https://localhost/abc' + '/subse'.repeat(39);
let refererUrl = url_255_characters + '/ext'.repeat(5) + '?param=' + 'x'.repeat(15);

bidderRequestParams.refererInfo.ref = refererUrl;
const fr = spec.buildRequests(bidRequests, bidderRequest).data.fr;
expect(fr).to.equal(url_255_characters);
});

it('should return crs parameter with document charset', function () {
let expected;
Expand Down