From 0261d035aa5ea5283b4e4f49316ec6b93922bacd Mon Sep 17 00:00:00 2001 From: ndigrazia Date: Tue, 28 Feb 2023 13:51:18 -0300 Subject: [PATCH 1/2] cut url whit url length is greater than 255 --- modules/eplanningBidAdapter.js | 16 +++++++- test/spec/modules/eplanningBidAdapter_spec.js | 37 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js index e230858487f..2216ab329b0 100644 --- a/modules/eplanningBidAdapter.js +++ b/modules/eplanningBidAdapter.js @@ -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, @@ -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 @@ -70,7 +71,7 @@ export const spec = { } if (referrerUrl) { - params.fr = referrerUrl; + params.fr = cutUrl(referrerUrl); } if (bidderRequest && bidderRequest.gdprConsent) { @@ -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 { diff --git a/test/spec/modules/eplanningBidAdapter_spec.js b/test/spec/modules/eplanningBidAdapter_spec.js index cb8393a29b8..80b2a5e31e7 100644 --- a/test/spec/modules/eplanningBidAdapter_spec.js +++ b/test/spec/modules/eplanningBidAdapter_spec.js @@ -729,11 +729,48 @@ 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, + url_255_characters = "https://localhost/abc" + "/subse".repeat(39), + 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, + url_255_characters = "https://localhost/abc" + "/subse".repeat(39), + 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; From bdc15d03f0e39c926d5f02ce512812851db5d1bb Mon Sep 17 00:00:00 2001 From: ndigrazia Date: Tue, 28 Feb 2023 15:35:03 -0300 Subject: [PATCH 2/2] Fix lint --- test/spec/modules/eplanningBidAdapter_spec.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/spec/modules/eplanningBidAdapter_spec.js b/test/spec/modules/eplanningBidAdapter_spec.js index 80b2a5e31e7..1a6cfd7afe4 100644 --- a/test/spec/modules/eplanningBidAdapter_spec.js +++ b/test/spec/modules/eplanningBidAdapter_spec.js @@ -732,16 +732,15 @@ describe('E-Planning Adapter', function () { 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); + 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, - url_255_characters = "https://localhost/abc" + "/subse".repeat(39), - refererUrl = url_255_characters + "/ext".repeat(5) + "?param=" + "x".repeat(15); - + 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; @@ -756,16 +755,15 @@ describe('E-Planning Adapter', function () { 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); + 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, - url_255_characters = "https://localhost/abc" + "/subse".repeat(39), - refererUrl = url_255_characters + "/ext".repeat(5) + "?param=" + "x".repeat(15); - + 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;