From b0bbcf6028dcf3b9e25dacb1aee06a79f45f9e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milorad=20FIlipovi=C4=87?= Date: Wed, 16 Nov 2022 09:21:30 +0100 Subject: [PATCH] fix(editor): Fix zero treated as missing value in resource locator (#4612) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 Adding a type guard to validate resource locator parameter values * ✔️ Fixing a linting error Co-authored-by: Michael Kret --- packages/workflow/src/NodeHelpers.ts | 3 ++- packages/workflow/src/type-guards.ts | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 650cb629b4..1d8cd4d5ee 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -38,6 +38,7 @@ import { NodeParameterValue, WebhookHttpMethod, } from './Interfaces'; +import { isValidResourceLocatorParameterValue } from './type-guards'; import { deepCopy } from './utils'; import type { Workflow } from './Workflow'; @@ -1150,7 +1151,7 @@ export function addToIssuesIfMissing( (nodeProperties.type === 'dateTime' && value === undefined) || (nodeProperties.type === 'options' && (value === '' || value === undefined)) || (nodeProperties.type === 'resourceLocator' && - (!value || (typeof value === 'object' && !value.value))) + !isValidResourceLocatorParameterValue(value as INodeParameterResourceLocator)) ) { // Parameter is required but empty if (foundIssues.parameters === undefined) { diff --git a/packages/workflow/src/type-guards.ts b/packages/workflow/src/type-guards.ts index 1cc53aa620..a669c254ef 100644 --- a/packages/workflow/src/type-guards.ts +++ b/packages/workflow/src/type-guards.ts @@ -1,4 +1,9 @@ -import { INodeProperties, INodePropertyOptions, INodePropertyCollection } from './Interfaces'; +import { + INodeProperties, + INodePropertyOptions, + INodePropertyCollection, + INodeParameterResourceLocator, +} from './Interfaces'; export const isINodeProperties = ( item: INodePropertyOptions | INodeProperties | INodePropertyCollection, @@ -25,3 +30,16 @@ export const isINodePropertyCollectionList = ( ): items is INodePropertyCollection[] => { return Array.isArray(items) && items.every(isINodePropertyCollection); }; + +export const isValidResourceLocatorParameterValue = ( + value: INodeParameterResourceLocator, +): boolean => { + if (typeof value === 'object') { + if (typeof value.value === 'number') { + return true; // Accept all numbers + } + return !!value.value; + } else { + return !!value; + } +};