🐛 (condition) Fix condition parsing with value "null"
This commit is contained in:
@@ -20,13 +20,14 @@ const executeComparison =
|
|||||||
(variables: Variable[]) =>
|
(variables: Variable[]) =>
|
||||||
(comparison: Comparison): boolean => {
|
(comparison: Comparison): boolean => {
|
||||||
if (!comparison?.variableId) return false
|
if (!comparison?.variableId) return false
|
||||||
const inputValue = variables.find(
|
const inputValue =
|
||||||
(v) => v.id === comparison.variableId
|
variables.find((v) => v.id === comparison.variableId)?.value ?? null
|
||||||
)?.value
|
if (isNotDefined(comparison.value)) return false
|
||||||
const value =
|
const value =
|
||||||
findUniqueVariableValue(variables)(comparison.value) ??
|
comparison.value === 'undefined' || comparison.value === 'null'
|
||||||
parseVariables(variables)(comparison.value)
|
? null
|
||||||
if (isNotDefined(value)) return false
|
: findUniqueVariableValue(variables)(comparison.value) ??
|
||||||
|
parseVariables(variables)(comparison.value)
|
||||||
if (isNotDefined(comparison.comparisonOperator)) return false
|
if (isNotDefined(comparison.comparisonOperator)) return false
|
||||||
switch (comparison.comparisonOperator) {
|
switch (comparison.comparisonOperator) {
|
||||||
case ComparisonOperators.CONTAINS: {
|
case ComparisonOperators.CONTAINS: {
|
||||||
@@ -50,7 +51,7 @@ const executeComparison =
|
|||||||
return compare((a, b) => a !== b, inputValue, value, true)
|
return compare((a, b) => a !== b, inputValue, value, true)
|
||||||
}
|
}
|
||||||
case ComparisonOperators.GREATER: {
|
case ComparisonOperators.GREATER: {
|
||||||
if (isNotDefined(inputValue)) return false
|
if (isNotDefined(inputValue) || isNotDefined(value)) return false
|
||||||
if (typeof inputValue === 'string') {
|
if (typeof inputValue === 'string') {
|
||||||
if (typeof value === 'string')
|
if (typeof value === 'string')
|
||||||
return parseFloat(inputValue) > parseFloat(value)
|
return parseFloat(inputValue) > parseFloat(value)
|
||||||
@@ -61,7 +62,7 @@ const executeComparison =
|
|||||||
return inputValue.length > value.length
|
return inputValue.length > value.length
|
||||||
}
|
}
|
||||||
case ComparisonOperators.LESS: {
|
case ComparisonOperators.LESS: {
|
||||||
if (isNotDefined(inputValue)) return false
|
if (isNotDefined(inputValue) || isNotDefined(value)) return false
|
||||||
if (typeof inputValue === 'string') {
|
if (typeof inputValue === 'string') {
|
||||||
if (typeof value === 'string')
|
if (typeof value === 'string')
|
||||||
return parseFloat(inputValue) < parseFloat(value)
|
return parseFloat(inputValue) < parseFloat(value)
|
||||||
@@ -96,18 +97,17 @@ const executeComparison =
|
|||||||
|
|
||||||
const compare = (
|
const compare = (
|
||||||
compareStrings: (a: string | null, b: string | null) => boolean,
|
compareStrings: (a: string | null, b: string | null) => boolean,
|
||||||
a: Variable['value'],
|
a: Exclude<Variable['value'], undefined>,
|
||||||
b: Variable['value'],
|
b: Exclude<Variable['value'], undefined>,
|
||||||
defaultReturnValue = false
|
defaultReturnValue = false
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if (!a || !b) return defaultReturnValue
|
if (!a || typeof a === 'string') {
|
||||||
if (typeof a === 'string') {
|
if (!b || typeof b === 'string') return compareStrings(a, b)
|
||||||
if (typeof b === 'string') return compareStrings(a, b)
|
|
||||||
return defaultReturnValue === true
|
return defaultReturnValue === true
|
||||||
? b.every((b) => compareStrings(a, b))
|
? b.every((b) => compareStrings(a, b))
|
||||||
: b.some((b) => compareStrings(a, b))
|
: b.some((b) => compareStrings(a, b))
|
||||||
}
|
}
|
||||||
if (typeof b === 'string') {
|
if (!b || typeof b === 'string') {
|
||||||
return defaultReturnValue === true
|
return defaultReturnValue === true
|
||||||
? a.every((a) => compareStrings(a, b))
|
? a.every((a) => compareStrings(a, b))
|
||||||
: a.some((a) => compareStrings(a, b))
|
: a.some((a) => compareStrings(a, b))
|
||||||
|
|||||||
Reference in New Issue
Block a user