From 496d3574c6f8df389331ec92fd330efb652f65e6 Mon Sep 17 00:00:00 2001 From: Piotr Grzesik Date: Wed, 17 Feb 2021 14:11:41 +0100 Subject: [PATCH] fix(Variables): Properly resolve vars if `prototype` in path --- lib/classes/Variables.js | 5 ++++- test/fixtures/variables/serverless.yml | 2 ++ test/unit/lib/classes/Variables.test.js | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/classes/Variables.js b/lib/classes/Variables.js index bf417551c..00d7d7292 100644 --- a/lib/classes/Variables.js +++ b/lib/classes/Variables.js @@ -308,7 +308,10 @@ class Variables { return BbPromise.all(populations).then((results) => results.forEach((result) => { if (result.value !== result.populated) { - _.set(target, result.path, result.populated); + const pathArray = Array.isArray(result.path) ? result.path : result.path.split('.'); + let obj = target; + for (const property of pathArray.slice(0, -1)) obj = obj[property]; + obj[_.last(pathArray)] = result.populated; } }) ); diff --git a/test/fixtures/variables/serverless.yml b/test/fixtures/variables/serverless.yml index 7badeb78c..919858992 100644 --- a/test/fixtures/variables/serverless.yml +++ b/test/fixtures/variables/serverless.yml @@ -17,3 +17,5 @@ custom: nestedVal: prop: resolvedNested nestedReference: ${self:custom.${self:custom.nestedRef}.prop} + prototype: + nestedInPrototype: ${file(config.json):foo}-in-prototype diff --git a/test/unit/lib/classes/Variables.test.js b/test/unit/lib/classes/Variables.test.js index 3f98215f0..cfb1e4129 100644 --- a/test/unit/lib/classes/Variables.test.js +++ b/test/unit/lib/classes/Variables.test.js @@ -2816,6 +2816,10 @@ describe('test/unit/lib/classes/Variables.test.js', () => { expect(processedConfig.custom.nestedReference).to.equal('resolvedNested'); }); + it('should handle resolving variables when `prototype` is part of the path', async () => { + expect(processedConfig.custom.prototype.nestedInPrototype).to.equal('bar-in-prototype'); + }); + describe('variable resolving', () => { describe('when unresolvedVariablesNotificationMode is set to "error"', () => { it('should error for missing "environment variable" type variables', async () => {