Skip to content

Commit

Permalink
fix(IF Node): Fix "Is Empty" and "Is Not Empty" operation fails for d…
Browse files Browse the repository at this point in the history
…ate objects (#4670)

* IF node isEmtpy and IsNotEmpty operation: ignore empty date objects
* IF node isEmtpy and IsNotEmpty operation: treat invalid dates as empty
  • Loading branch information
maspio authored Nov 21, 2022
1 parent 63ceea2 commit 753f4c9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/nodes-base/nodes/If/If.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]*)$'));
Expand Down

0 comments on commit 753f4c9

Please sign in to comment.