From 2375448038d57ca57d8a052a2fe635af9d528d1d Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Mon, 16 Dec 2024 14:18:33 +0100 Subject: [PATCH] fix(no-bpmndi): prevent crash when `bpmndi:BPMNDiagram` is missing --- rules/no-bpmndi.js | 2 +- test/rules/no-bpmndi.mjs | 9 ++++++++- test/rules/no-bpmndi/invalid-no-bpmn-diagram.bpmn | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/rules/no-bpmndi/invalid-no-bpmn-diagram.bpmn diff --git a/rules/no-bpmndi.js b/rules/no-bpmndi.js index c2b1e3b..35005a7 100644 --- a/rules/no-bpmndi.js +++ b/rules/no-bpmndi.js @@ -103,7 +103,7 @@ function getAllBpmnElements(rootElements) { */ function getAllDiBpmnReferences(definitionsNode) { return flatten( - definitionsNode.diagrams.map((diagram) => { + definitionsNode.get('diagrams').map((diagram) => { const diElements = diagram.plane.planeElement || []; diff --git a/test/rules/no-bpmndi.mjs b/test/rules/no-bpmndi.mjs index 68d369a..9977617 100644 --- a/test/rules/no-bpmndi.mjs +++ b/test/rules/no-bpmndi.mjs @@ -170,6 +170,13 @@ RuleTester.verify('no-bpmndi', rule, { id: 'danglingMessageFlow', message: 'Element is missing bpmndi' } - } + }, + { + moddleElement: readModdle(__dirname + '/no-bpmndi/invalid-no-bpmn-diagram.bpmn'), + report: { + id: 'StartEvent_1', + message: 'Element is missing bpmndi' + } + }, ] }); diff --git a/test/rules/no-bpmndi/invalid-no-bpmn-diagram.bpmn b/test/rules/no-bpmndi/invalid-no-bpmn-diagram.bpmn new file mode 100644 index 0000000..b127d06 --- /dev/null +++ b/test/rules/no-bpmndi/invalid-no-bpmn-diagram.bpmn @@ -0,0 +1,6 @@ + + + + + +