From 30c8efc4cc9b25fabc8d9c56e8c29e7e77c04325 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Thu, 2 May 2024 17:01:00 +0200 Subject: [PATCH] fix: Cast boolean values in filter parameter (#9260) --- .../src/NodeParameters/FilterParameter.ts | 12 ++++++--- .../workflow/test/FilterParameter.test.ts | 25 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/packages/workflow/src/NodeParameters/FilterParameter.ts b/packages/workflow/src/NodeParameters/FilterParameter.ts index fdaee8e71daa4..5196eb0af132d 100644 --- a/packages/workflow/src/NodeParameters/FilterParameter.ts +++ b/packages/workflow/src/NodeParameters/FilterParameter.ts @@ -32,9 +32,15 @@ function parseSingleFilterValue( type: FilterOperatorType, strict = false, ): ValidationResult { - return type === 'any' || value === null || value === undefined - ? ({ valid: true, newValue: value } as ValidationResult) - : validateFieldType('filter', value, type, { strict, parseStrings: true }); + if (type === 'any' || value === null || value === undefined) { + return { valid: true, newValue: value } as ValidationResult; + } + + if (type === 'boolean' && !strict) { + return { valid: true, newValue: Boolean(value) }; + } + + return validateFieldType('filter', value, type, { strict, parseStrings: true }); } const withIndefiniteArticle = (noun: string): string => { diff --git a/packages/workflow/test/FilterParameter.test.ts b/packages/workflow/test/FilterParameter.test.ts index b8cd8bac7eb5a..197ab8508c010 100644 --- a/packages/workflow/test/FilterParameter.test.ts +++ b/packages/workflow/test/FilterParameter.test.ts @@ -177,6 +177,27 @@ describe('FilterParameter', () => { leftValue: 'true', operator: { operation: 'true', type: 'boolean' }, }, + { + id: '3', + leftValue: '', + operator: { operation: 'false', type: 'boolean' }, + }, + + { + id: '4', + leftValue: 0, + operator: { operation: 'false', type: 'boolean' }, + }, + { + id: '5', + leftValue: 1, + operator: { operation: 'true', type: 'boolean' }, + }, + { + id: '6', + leftValue: 'a string', + operator: { operation: 'true', type: 'boolean' }, + }, ], options: { typeValidation: 'loose' }, }), @@ -194,14 +215,14 @@ describe('FilterParameter', () => { id: '1', leftValue: 'a string', rightValue: 15, - operator: { operation: 'equals', type: 'boolean' }, + operator: { operation: 'equals', type: 'number' }, }, ], options: { typeValidation: 'loose' }, }), ), ).toThrowError( - "Conversion error: the string 'a string' can't be converted to a boolean [condition 0, item 0]", + "Conversion error: the string 'a string' can't be converted to a number [condition 0, item 0]", ); }); });