From 8db03c90ffba68ebda800d2a009452cd09f7bf7f Mon Sep 17 00:00:00 2001 From: Steven Noorbergen <91969936+steven-xaroth@users.noreply.github.com> Date: Mon, 24 Jan 2022 14:03:32 +0100 Subject: [PATCH] fix(Variables): Fix too eager nested resolution tracking (#10554) --- lib/configuration/variables/resolve.js | 4 ++-- .../lib/configuration/variables/sources/file.test.js | 4 ++++ .../sources/fixture/file-function-many-variables.js | 5 +++++ .../fixture/file-function-many-variables.yaml | 12 ++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/unit/lib/configuration/variables/sources/fixture/file-function-many-variables.js create mode 100644 test/unit/lib/configuration/variables/sources/fixture/file-function-many-variables.yaml diff --git a/lib/configuration/variables/resolve.js b/lib/configuration/variables/resolve.js index bef1748f8..d6ee3c185 100644 --- a/lib/configuration/variables/resolve.js +++ b/lib/configuration/variables/resolve.js @@ -338,7 +338,7 @@ class VariablesResolver { valueMeta.variables = valueVariables; delete valueMeta.sourceValues; await this.resolveVariables(resolutionBatchId, propertyPath, valueMeta); - await this.resolveInternalResult(resolutionBatchId, propertyPath, valueMeta, --nestTracker); + await this.resolveInternalResult(resolutionBatchId, propertyPath, valueMeta, nestTracker - 1); return; } const valueEntries = (() => { @@ -353,7 +353,7 @@ class VariablesResolver { resolutionBatchId, propertyPath, propertyValueMeta, - --nestTracker + nestTracker - 1 ); const propertyKeyPathKeys = propertyKeyPath.split('\0'); const targetKey = propertyKeyPathKeys[propertyKeyPathKeys.length - 1]; diff --git a/test/unit/lib/configuration/variables/sources/file.test.js b/test/unit/lib/configuration/variables/sources/file.test.js index fc5789c6a..c43fa9422 100644 --- a/test/unit/lib/configuration/variables/sources/file.test.js +++ b/test/unit/lib/configuration/variables/sources/file.test.js @@ -25,6 +25,7 @@ describe('test/unit/lib/configuration/variables/sources/file.test.js', () => { addressSupport: '${file(file.json):result}', jsFunctionResolveVariable: '${file(file-function-variable.js)}', jsFunctionResolveVariableMissingSource: '${file(file-function-variable-missing-source.js)}', + jsFunctionResolveManyVariables: '${file(file-function-many-variables.js)}', jsPropertyFunctionResolveVariable: '${file(file-property-function-variable.js):property}', jsPropertyFunctionResolveVariableMissingSource: '${file(file-property-function-variable-missing-source.js):property}', @@ -101,6 +102,9 @@ describe('test/unit/lib/configuration/variables/sources/file.test.js', () => { expect(configuration.jsPropertyFunctionResolveVariable).to.deep.equal({ varResult: { result: 'json' }, }); + expect(configuration.jsFunctionResolveManyVariables).to.deep.equal({ + varResult: { result: ['yml', 'yml', 'yml', 'yml', 'yml', 'yml', 'yml', 'yml', 'yml', 'yml'] }, + }); }); it('should resolve variables across address resolution', () => { diff --git a/test/unit/lib/configuration/variables/sources/fixture/file-function-many-variables.js b/test/unit/lib/configuration/variables/sources/fixture/file-function-many-variables.js new file mode 100644 index 000000000..9bc3345e9 --- /dev/null +++ b/test/unit/lib/configuration/variables/sources/fixture/file-function-many-variables.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = async ({ resolveVariable }) => ({ + varResult: await resolveVariable('file(file-function-many-variables.yaml)'), +}); diff --git a/test/unit/lib/configuration/variables/sources/fixture/file-function-many-variables.yaml b/test/unit/lib/configuration/variables/sources/fixture/file-function-many-variables.yaml new file mode 100644 index 000000000..025a204d3 --- /dev/null +++ b/test/unit/lib/configuration/variables/sources/fixture/file-function-many-variables.yaml @@ -0,0 +1,12 @@ +# The resolve nest depth is 10, so we have to resolve at least 10 files to ensure it's not being hit. +result: + - ${file(./file.yml):result} + - ${file(./file.yml):result} + - ${file(./file.yml):result} + - ${file(./file.yml):result} + - ${file(./file.yml):result} + - ${file(./file.yml):result} + - ${file(./file.yml):result} + - ${file(./file.yml):result} + - ${file(./file.yml):result} + - ${file(./file.yml):result}