fix(editor): Fix zero treated as missing value in resource locator (#4612)

* 🐛 Adding a type guard to validate resource locator parameter values
* ✔️ Fixing a linting error
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
Milorad FIlipović 2022-11-16 09:21:30 +01:00 committed by GitHub
parent 53d2526cd1
commit b0bbcf6028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -38,6 +38,7 @@ import {
NodeParameterValue, NodeParameterValue,
WebhookHttpMethod, WebhookHttpMethod,
} from './Interfaces'; } from './Interfaces';
import { isValidResourceLocatorParameterValue } from './type-guards';
import { deepCopy } from './utils'; import { deepCopy } from './utils';
import type { Workflow } from './Workflow'; import type { Workflow } from './Workflow';
@ -1150,7 +1151,7 @@ export function addToIssuesIfMissing(
(nodeProperties.type === 'dateTime' && value === undefined) || (nodeProperties.type === 'dateTime' && value === undefined) ||
(nodeProperties.type === 'options' && (value === '' || value === undefined)) || (nodeProperties.type === 'options' && (value === '' || value === undefined)) ||
(nodeProperties.type === 'resourceLocator' && (nodeProperties.type === 'resourceLocator' &&
(!value || (typeof value === 'object' && !value.value))) !isValidResourceLocatorParameterValue(value as INodeParameterResourceLocator))
) { ) {
// Parameter is required but empty // Parameter is required but empty
if (foundIssues.parameters === undefined) { if (foundIssues.parameters === undefined) {

View file

@ -1,4 +1,9 @@
import { INodeProperties, INodePropertyOptions, INodePropertyCollection } from './Interfaces'; import {
INodeProperties,
INodePropertyOptions,
INodePropertyCollection,
INodeParameterResourceLocator,
} from './Interfaces';
export const isINodeProperties = ( export const isINodeProperties = (
item: INodePropertyOptions | INodeProperties | INodePropertyCollection, item: INodePropertyOptions | INodeProperties | INodePropertyCollection,
@ -25,3 +30,16 @@ export const isINodePropertyCollectionList = (
): items is INodePropertyCollection[] => { ): items is INodePropertyCollection[] => {
return Array.isArray(items) && items.every(isINodePropertyCollection); 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;
}
};