Skip to content

Commit 30c8efc

Browse files
authored
fix: Cast boolean values in filter parameter (#9260)
1 parent d3e0640 commit 30c8efc

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

packages/workflow/src/NodeParameters/FilterParameter.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ function parseSingleFilterValue(
3232
type: FilterOperatorType,
3333
strict = false,
3434
): ValidationResult {
35-
return type === 'any' || value === null || value === undefined
36-
? ({ valid: true, newValue: value } as ValidationResult)
37-
: validateFieldType('filter', value, type, { strict, parseStrings: true });
35+
if (type === 'any' || value === null || value === undefined) {
36+
return { valid: true, newValue: value } as ValidationResult;
37+
}
38+
39+
if (type === 'boolean' && !strict) {
40+
return { valid: true, newValue: Boolean(value) };
41+
}
42+
43+
return validateFieldType('filter', value, type, { strict, parseStrings: true });
3844
}
3945

4046
const withIndefiniteArticle = (noun: string): string => {

packages/workflow/test/FilterParameter.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,27 @@ describe('FilterParameter', () => {
177177
leftValue: 'true',
178178
operator: { operation: 'true', type: 'boolean' },
179179
},
180+
{
181+
id: '3',
182+
leftValue: '',
183+
operator: { operation: 'false', type: 'boolean' },
184+
},
185+
186+
{
187+
id: '4',
188+
leftValue: 0,
189+
operator: { operation: 'false', type: 'boolean' },
190+
},
191+
{
192+
id: '5',
193+
leftValue: 1,
194+
operator: { operation: 'true', type: 'boolean' },
195+
},
196+
{
197+
id: '6',
198+
leftValue: 'a string',
199+
operator: { operation: 'true', type: 'boolean' },
200+
},
180201
],
181202
options: { typeValidation: 'loose' },
182203
}),
@@ -194,14 +215,14 @@ describe('FilterParameter', () => {
194215
id: '1',
195216
leftValue: 'a string',
196217
rightValue: 15,
197-
operator: { operation: 'equals', type: 'boolean' },
218+
operator: { operation: 'equals', type: 'number' },
198219
},
199220
],
200221
options: { typeValidation: 'loose' },
201222
}),
202223
),
203224
).toThrowError(
204-
"Conversion error: the string 'a string' can't be converted to a boolean [condition 0, item 0]",
225+
"Conversion error: the string 'a string' can't be converted to a number [condition 0, item 0]",
205226
);
206227
});
207228
});

0 commit comments

Comments
 (0)