From bb18807b30cc86743b23084b25380740d1720e44 Mon Sep 17 00:00:00 2001 From: Robert Ray Martinez III Date: Wed, 2 Sep 2020 05:42:55 -0700 Subject: [PATCH] Price Floors: Fix bug when caching floor lookup (#5673) * Cannot pass cached floor by reference, adjustments break it! * fix typo Co-authored-by: Leif Wickland Co-authored-by: Leif Wickland --- modules/priceFloors.js | 2 +- test/spec/modules/priceFloors_spec.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/priceFloors.js b/modules/priceFloors.js index 2acd21918ef..1b865e05c0a 100644 --- a/modules/priceFloors.js +++ b/modules/priceFloors.js @@ -103,7 +103,7 @@ export function getFirstMatchingFloor(floorData, bidObject, responseObject = {}) // if we already have gotten the matching rule from this matching input then use it! No need to look again let previousMatch = utils.deepAccess(floorData, `matchingInputs.${matchingInput}`); if (previousMatch) { - return previousMatch; + return {...previousMatch}; } let allPossibleMatches = generatePossibleEnumerations(fieldValues, utils.deepAccess(floorData, 'schema.delimiter') || '|'); let matchingRule = find(allPossibleMatches, hashValue => floorData.values.hasOwnProperty(hashValue)); diff --git a/test/spec/modules/priceFloors_spec.js b/test/spec/modules/priceFloors_spec.js index d4ac2e5ad72..ae45244f03d 100644 --- a/test/spec/modules/priceFloors_spec.js +++ b/test/spec/modules/priceFloors_spec.js @@ -182,6 +182,20 @@ describe('the price floors module', function () { matchingRule: '*' }); }); + it('does not alter cached matched input if conversion occurs', function () { + let inputData = {...basicFloorData}; + [0.2, 0.4, 0.6, 0.8].forEach(modifier => { + let result = getFirstMatchingFloor(inputData, basicBidRequest, {mediaType: 'banner', size: '*'}); + // result should always be the same + expect(result).to.deep.equal({ + matchingFloor: 1.0, + matchingData: 'banner', + matchingRule: 'banner' + }); + // make sure a post retrieval adjustment does not alter the cached floor + result.matchingFloor = result.matchingFloor * modifier; + }); + }); it('selects the right floor for different sizes', function () { let inputFloorData = { currency: 'USD',