fix(IF Node): Fix "Is Empty" and "Is Not Empty" operation fails for date objects (#4670)

* IF node isEmtpy and IsNotEmpty operation: ignore empty date objects
* IF node isEmtpy and IsNotEmpty operation: treat invalid dates as empty
This commit is contained in:
Marcus 2022-11-21 18:26:59 +01:00 committed by GitHub
parent 63ceea2f60
commit 753f4c9a7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -315,6 +315,9 @@ export class If implements INodeType {
let item: INodeExecutionData;
let combineOperation: string;
const isDateObject = (value: NodeParameterValue) => Object.prototype.toString.call(value) === '[object Date]';
const isDateInvalid = (value: NodeParameterValue) => value?.toString() === 'Invalid Date';
// The compare operations
const compareOperationFunctions: {
[key: string]: (value1: NodeParameterValue, value2: NodeParameterValue) => boolean;
@ -347,15 +350,17 @@ export class If implements INodeType {
!(value1 as string).startsWith(value2 as string),
isEmpty: (value1: NodeParameterValue) =>
[undefined, null, '', NaN].includes(value1 as string) ||
(typeof value1 === 'object' && value1 !== null
(typeof value1 === 'object' && value1 !== null && !isDateObject(value1)
? Object.entries(value1 as string).length === 0
: false),
: false) ||
(isDateObject(value1) && isDateInvalid(value1)),
isNotEmpty: (value1: NodeParameterValue) =>
!(
[undefined, null, '', NaN].includes(value1 as string) ||
(typeof value1 === 'object' && value1 !== null
(typeof value1 === 'object' && value1 !== null && !isDateObject(value1)
? Object.entries(value1 as string).length === 0
: false)
: false) ||
(isDateObject(value1) && isDateInvalid(value1))
),
regex: (value1: NodeParameterValue, value2: NodeParameterValue) => {
const regexMatch = (value2 || '').toString().match(new RegExp('^/(.*?)/([gimusy]*)$'));