From f31ecb6713de535f66a8705d829a2a99e4ff549c Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 4 Aug 2022 16:46:05 +0200 Subject: [PATCH] fix: ignore null properties Related to https://github.com/camunda/camunda-modeler/issues/3067 --- rules/utils/element.js | 3 ++- test/helper.js | 2 +- test/utils/element.spec.js | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/rules/utils/element.js b/rules/utils/element.js index e0129686..cdd297a6 100644 --- a/rules/utils/element.js +++ b/rules/utils/element.js @@ -1,6 +1,7 @@ const { isArray, isDefined, + isNil, some } = require('min-dash'); @@ -147,7 +148,7 @@ module.exports.hasProperties = function(node, properties, parentNode = null) { ]; } - if (propertyChecks.allowed === false && isDefined(propertyValue)) { + if (propertyChecks.allowed === false && isDefined(propertyValue) && !isNil(propertyValue)) { return [ ...results, { diff --git a/test/helper.js b/test/helper.js index e89f5474..592ec1ba 100644 --- a/test/helper.js +++ b/test/helper.js @@ -99,7 +99,7 @@ function createElement(type, properties) { }; const setParent = (property) => { - if (property.$type) { + if (property && property.$type) { const childModdleElement = property; childModdleElement.$parent = moddleElement; diff --git a/test/utils/element.spec.js b/test/utils/element.spec.js index b60527af..e0a6d435 100644 --- a/test/utils/element.spec.js +++ b/test/utils/element.spec.js @@ -456,7 +456,7 @@ describe('utils/element', function() { describe('allowed', function() { - it('should not return errors', function() { + it('should not return errors (undefined)', function() { // given const serviceTask = createElement('bpmn:ServiceTask'); @@ -473,6 +473,25 @@ describe('utils/element', function() { }); + it('should not return errors (null)', function() { + + // given + const serviceTask = createElement('bpmn:ServiceTask', { + modelerTemplate: null + }); + + // when + const errors = hasProperties(serviceTask, { + modelerTemplate: { + allowed: false + } + }); + + // then + expect(errors).to.be.empty; + }); + + it('should return errors', function() { // given