Skip to content

Commit

Permalink
Eplanning Bid Adapter : cut url when url size greater than 255 (prebi…
Browse files Browse the repository at this point in the history
…d#9606)

* cut url whit url length is greater than 255

* Fix lint
  • Loading branch information
fndigrazia authored Mar 1, 2023
1 parent 8275dc4 commit 6bd8a1d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
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

0 comments on commit 6bd8a1d

Please sign in to comment.