mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
fix: Cast boolean values in filter parameter (#9260)
This commit is contained in:
parent
d3e0640674
commit
30c8efc4cc
|
@ -32,9 +32,15 @@ function parseSingleFilterValue(
|
||||||
type: FilterOperatorType,
|
type: FilterOperatorType,
|
||||||
strict = false,
|
strict = false,
|
||||||
): ValidationResult {
|
): ValidationResult {
|
||||||
return type === 'any' || value === null || value === undefined
|
if (type === 'any' || value === null || value === undefined) {
|
||||||
? ({ valid: true, newValue: value } as ValidationResult)
|
return { valid: true, newValue: value } as ValidationResult;
|
||||||
: validateFieldType('filter', value, type, { strict, parseStrings: true });
|
}
|
||||||
|
|
||||||
|
if (type === 'boolean' && !strict) {
|
||||||
|
return { valid: true, newValue: Boolean(value) };
|
||||||
|
}
|
||||||
|
|
||||||
|
return validateFieldType('filter', value, type, { strict, parseStrings: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const withIndefiniteArticle = (noun: string): string => {
|
const withIndefiniteArticle = (noun: string): string => {
|
||||||
|
|
|
@ -177,6 +177,27 @@ describe('FilterParameter', () => {
|
||||||
leftValue: 'true',
|
leftValue: 'true',
|
||||||
operator: { operation: 'true', type: 'boolean' },
|
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' },
|
options: { typeValidation: 'loose' },
|
||||||
}),
|
}),
|
||||||
|
@ -194,14 +215,14 @@ describe('FilterParameter', () => {
|
||||||
id: '1',
|
id: '1',
|
||||||
leftValue: 'a string',
|
leftValue: 'a string',
|
||||||
rightValue: 15,
|
rightValue: 15,
|
||||||
operator: { operation: 'equals', type: 'boolean' },
|
operator: { operation: 'equals', type: 'number' },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
options: { typeValidation: 'loose' },
|
options: { typeValidation: 'loose' },
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
).toThrowError(
|
).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]",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue