diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index 9bd0d1c7f6a..b307f534b18 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -18,6 +18,8 @@ const LOCAL_WINDOW = utils.getWindowTop(); const DEFAULT_PLAYBACK_METHOD = 2; const DEFAULT_START_DELAY = 0; const VAST_TIMEOUT = 15000; +const MAX_BANNER_REQUEST_URL_LENGTH = 8000; +const BANNER_REQUEST_PROPERTIES_TO_REDUCE = ['description', 'title', 'pr', 'page_url']; export const spec = { code: BIDDER_CODE, @@ -51,7 +53,7 @@ export const spec = { p: [], page_url: bidderRequest.refererInfo.referer, bust: new Date().getTime().toString(), - pr: bidderRequest.refererInfo.referer, + pr: (LOCAL_WINDOW.document && LOCAL_WINDOW.document.referrer) || '', scrd: LOCAL_WINDOW.devicePixelRatio || 0, dnt: getDNT(), description: getPageDescription(), @@ -92,6 +94,20 @@ export const spec = { } }); serverRequest.p = '[' + serverRequest.p.toString() + ']'; + + // check if url exceeded max length + const url = `${BANNER_SERVER_ENDPOINT}?${utils.parseQueryStringParameters(serverRequest)}`; + let extraCharacters = url.length - MAX_BANNER_REQUEST_URL_LENGTH; + if (extraCharacters > 0) { + for (let i = 0; i < BANNER_REQUEST_PROPERTIES_TO_REDUCE.length; i++) { + extraCharacters = shortcutProperty(extraCharacters, serverRequest, BANNER_REQUEST_PROPERTIES_TO_REDUCE[i]); + + if (extraCharacters <= 0) { + break; + } + } + } + serverRequests.push({ method: 'GET', url: BANNER_SERVER_ENDPOINT, @@ -273,7 +289,7 @@ function getPageDescription() { if (document.querySelector('meta[name="description"]')) { return document .querySelector('meta[name="description"]') - .getAttribute('content'); // Value of the description metadata from the publisher's page. + .getAttribute('content') || ''; // Value of the description metadata from the publisher's page. } else { return ''; } @@ -514,3 +530,25 @@ function validateVideoParams(bid) { return false; } } + +/** + * Shortcut object property and check if required characters count was deleted + * + * @param {number} extraCharacters, count of characters to remove + * @param {object} target, object on which string property length should be reduced + * @param {string} propertyName, name of property to reduce + * @return {number} 0 if required characters count was removed otherwise count of how many left + */ +function shortcutProperty(extraCharacters, target, propertyName) { + if (target[propertyName].length > extraCharacters) { + target[propertyName] = target[propertyName].substring(0, target[propertyName].length - extraCharacters); + + return 0 + } + + const charactersLeft = extraCharacters - target[propertyName].length; + + target[propertyName] = ''; + + return charactersLeft; +} diff --git a/test/spec/modules/yieldmoBidAdapter_spec.js b/test/spec/modules/yieldmoBidAdapter_spec.js index 17d63e41266..3b317f88dc6 100644 --- a/test/spec/modules/yieldmoBidAdapter_spec.js +++ b/test/spec/modules/yieldmoBidAdapter_spec.js @@ -281,6 +281,53 @@ describe('YieldmoAdapter', function () { const placementsData = JSON.parse(buildAndGetPlacementInfo([mockBannerBid()])); expect(placementsData[0].bidfloor).to.undefined; }); + + it('should not exceed max url length', () => { + const longString = new Array(8000).join('a'); + const localWindow = utils.getWindowTop(); + + const originalTitle = localWindow.document.title; + localWindow.document.title = longString; + + const request = spec.buildRequests( + [mockBannerBid()], + mockBidderRequest({ + refererInfo: { + numIframes: 1, + reachedTop: true, + referer: longString, + }, + }) + )[0]; + const url = `${request.url}?${utils.parseQueryStringParameters(request.data)}`; + + expect(url.length).equal(8000); + + localWindow.document.title = originalTitle; + }); + + it('should only shortcut properties rather then completely remove it', () => { + const longString = new Array(7516).join('a'); + const localWindow = utils.getWindowTop(); + + const originalTitle = localWindow.document.title; + localWindow.document.title = `testtitle${longString}`; + + const request = spec.buildRequests( + [mockBannerBid()], + mockBidderRequest({ + refererInfo: { + numIframes: 1, + reachedTop: true, + referer: longString, + }, + }) + )[0]; + + expect(request.data.title.length).greaterThan(0); + + localWindow.document.title = originalTitle; + }); }); describe('Instream video:', function () {