mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
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:
parent
63ceea2f60
commit
753f4c9a7d
|
@ -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]*)$'));
|
||||
|
|
Loading…
Reference in a new issue