From 100e3e1b533cf03943c8cb4c096bf859961faa51 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Wed, 26 Sep 2018 08:00:28 -0700 Subject: [PATCH] Bugfix: Issue 3111 (#3122) * bug fix for Prebid issue 3111 * adding try-catch around the fix * added a warning on exception handling * updated the message * using util.deepClone * changed variable name from original_bid to originalBid * unit test case for checking original object modification --- modules/pubmaticBidAdapter.js | 4 +++- test/spec/modules/pubmaticBidAdapter_spec.js | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 8b5a766e48b..452f6149091 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -319,7 +319,9 @@ export const spec = { var dctr = ''; var dctrLen; var dctrArr = []; - validBidRequests.forEach(bid => { + var bid; + validBidRequests.forEach(originalBid => { + bid = utils.deepClone(originalBid); _parseAdSlot(bid); if (bid.params.hasOwnProperty('video')) { if (!(bid.params.adSlot && bid.params.adUnit && bid.params.adUnitIndex)) { diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index e67ec1f11a2..be3b59c1a80 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -217,7 +217,13 @@ describe('PubMatic adapter', function () { }); describe('Request formation', function () { - it('Endpoint checking', function () { + it('buildRequests function should not modify original bidRequests object', function () { + let originalBidRequests = utils.deepClone(bidRequests); + let request = spec.buildRequests(bidRequests); + expect(bidRequests).to.deep.equal(originalBidRequests); + }); + + it('Endpoint checking', function () { let request = spec.buildRequests(bidRequests); expect(request.url).to.equal('//hbopenbid.pubmatic.com/translator?source=prebid-client'); expect(request.method).to.equal('POST');