From 145d1b6d9bde4c21892859b37647dd04782290e0 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Thu, 7 Mar 2024 14:02:08 +0100 Subject: [PATCH] fix(VariableResolver): correctly filter out already existing properties related to https://github.com/camunda/camunda-modeler/issues/4139 --- lib/base/VariableResolver.js | 4 +- test/fixtures/zeebe/mappings/mappings.bpmn | 75 ---------------------- test/fixtures/zeebe/mappings/merging.bpmn | 38 ++++++++++- test/spec/zeebe/Mappings.spec.js | 23 +++++++ 4 files changed, 62 insertions(+), 78 deletions(-) delete mode 100644 test/fixtures/zeebe/mappings/mappings.bpmn diff --git a/lib/base/VariableResolver.js b/lib/base/VariableResolver.js index 3c051ff..83a9dd1 100644 --- a/lib/base/VariableResolver.js +++ b/lib/base/VariableResolver.js @@ -309,9 +309,9 @@ function merge(property, target, source) { target[property] = []; } - const originToAdd = source[property].filter(o => !target.origin.includes(o)); + const propertiesToAdd = source[property].filter(o => !target[property].includes(o)); - target[property].push(...originToAdd); + target[property].push(...propertiesToAdd); } export function mergeEntries(target, source, visited = []) { diff --git a/test/fixtures/zeebe/mappings/mappings.bpmn b/test/fixtures/zeebe/mappings/mappings.bpmn deleted file mode 100644 index 9c475c5..0000000 --- a/test/fixtures/zeebe/mappings/mappings.bpmn +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/fixtures/zeebe/mappings/merging.bpmn b/test/fixtures/zeebe/mappings/merging.bpmn index 4cee764..44d27ed 100644 --- a/test/fixtures/zeebe/mappings/merging.bpmn +++ b/test/fixtures/zeebe/mappings/merging.bpmn @@ -1,8 +1,9 @@ - + + @@ -36,6 +37,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -59,6 +88,13 @@ + + + + + + + diff --git a/test/spec/zeebe/Mappings.spec.js b/test/spec/zeebe/Mappings.spec.js index 1ca1bad..18dff03 100644 --- a/test/spec/zeebe/Mappings.spec.js +++ b/test/spec/zeebe/Mappings.spec.js @@ -247,6 +247,29 @@ describe('ZeebeVariableResolver - Variable Mappings', function() { ]); })); + + it('should handle many merge operations', inject(async function(variableResolver, elementRegistry) { + + // given + const root = elementRegistry.get('Participant_3'); + + createProvider({ + variables: [], + variableResolver + }); + + // when + // this failed previously in an infinite loop, cf. https://github.com/camunda/camunda-modeler/issues/4139 + const variables = await variableResolver.getVariablesForElement(root.businessObject.processRef); + + // then + expect(variables).to.variableEqual([ + { + name: 'foo' + } + ]); + })); + });