Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cast boolean values in filter parameter #9260

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/workflow/src/NodeParameters/FilterParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
25 changes: 23 additions & 2 deletions packages/workflow/test/FilterParameter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
}),
Expand All @@ -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]",
);
});
});
Expand Down
Loading