Skip to content

Commit 2fe2093

Browse files
authored
fix: resolve direct path expressions on Any-typed variable as Any (#98)
Related to #87
1 parent fadfb4e commit 2fe2093

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

lib/zeebe/util/feelUtility.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ function resolveReferences(variablesToResolve, allVariables) {
106106
computedResult.value.info = expression;
107107
}
108108

109+
// If the result is null but a referenced variable is "Any"-typed (unknown
110+
// structure), accessing a property on it should also yield "Any", not "Null".
111+
// cf. https://github.com/bpmn-io/variable-resolver/issues/87
112+
else if (computedResult.value.atomicValue === null &&
113+
unresolvedRoots.some(name => {
114+
const entry = scopedContext.entries[name];
115+
return entry instanceof EntriesContext &&
116+
getType(entry.value) === 'Any';
117+
})) {
118+
computedResult = EntriesContext.of(undefined);
119+
computedResult.value.info = expression;
120+
}
121+
109122
// Ensure we don't copy the scope from the mapped variable
110123
computedResult.scope = variable.scope;
111124

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.44.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.1.0">
3+
<bpmn:process id="Process_1" isExecutable="true">
4+
<bpmn:subProcess id="SubProcess_1" name="SubProcess_1">
5+
<bpmn:extensionElements>
6+
<zeebe:ioMapping>
7+
<zeebe:input source="=agent.context" target="agentContext" />
8+
<zeebe:output source="=agent" target="agent" />
9+
</zeebe:ioMapping>
10+
</bpmn:extensionElements>
11+
</bpmn:subProcess>
12+
</bpmn:process>
13+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
14+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
15+
<bpmndi:BPMNShape id="SubProcess_1_di" bpmnElement="SubProcess_1" isExpanded="true">
16+
<dc:Bounds x="160" y="80" width="350" height="200" />
17+
<bpmndi:BPMNLabel />
18+
</bpmndi:BPMNShape>
19+
</bpmndi:BPMNPlane>
20+
</bpmndi:BPMNDiagram>
21+
</bpmn:definitions>

test/spec/zeebe/Mappings.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import propagationXML from 'test/fixtures/zeebe/mappings/propagation.bpmn';
2424
import scriptTaskXML from 'test/fixtures/zeebe/mappings/script-task.bpmn';
2525
import scriptTaskEmptyExpressionXML from 'test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn';
2626
import scriptTaskOutputNoNameXML from 'test/fixtures/zeebe/mappings/script-task-output-no-name.bpmn';
27+
import unresolvablePathExpressionXML from 'test/fixtures/zeebe/mappings/unresolvable-path-expression.bpmn';
2728

2829
import VariableProvider from 'lib/VariableProvider';
2930

@@ -474,6 +475,38 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
474475
});
475476

476477

478+
describe('Unresolvable path expression', function() {
479+
480+
beforeEach(bootstrap(unresolvablePathExpressionXML));
481+
482+
483+
it('should resolve unresolvable path expression as <Any>', inject(async function(variableResolver, elementRegistry) {
484+
485+
// given
486+
const subProcess = elementRegistry.get('SubProcess_1');
487+
488+
// when
489+
const variables = await variableResolver.getVariablesForElement(subProcess);
490+
491+
// then
492+
// cf. https://github.com/bpmn-io/variable-resolver/issues/87
493+
expect(variables).to.variableEqual([
494+
{
495+
name: 'agentContext',
496+
type: 'Any',
497+
info: '=agent.context'
498+
},
499+
{
500+
name: 'agent',
501+
type: 'Any',
502+
info: '=agent'
503+
}
504+
]);
505+
}));
506+
507+
});
508+
509+
477510
describe('Scope', function() {
478511

479512
beforeEach(bootstrap(scopeXML));

0 commit comments

Comments
 (0)