Skip to content

Commit cae7be4

Browse files
committed
🐛 (condition) Improve contains/not contains on list input
Closes baptisteArno#1430
1 parent d194fbe commit cae7be4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/bot-engine/blocks/logic/condition/executeCondition.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ const executeComparison =
3232
if (isNotDefined(comparison.comparisonOperator)) return false
3333
switch (comparison.comparisonOperator) {
3434
case ComparisonOperators.CONTAINS: {
35+
if (Array.isArray(inputValue)) {
36+
const equal = (a: string | null, b: string | null) => {
37+
if (typeof a === 'string' && typeof b === 'string')
38+
return a.normalize() === b.normalize()
39+
return a !== b
40+
}
41+
return compare(equal, inputValue, value, 'some')
42+
}
3543
const contains = (a: string | null, b: string | null) => {
3644
if (b === '' || !b || !a) return false
3745
return a
@@ -43,6 +51,14 @@ const executeComparison =
4351
return compare(contains, inputValue, value, 'some')
4452
}
4553
case ComparisonOperators.NOT_CONTAINS: {
54+
if (Array.isArray(inputValue)) {
55+
const notEqual = (a: string | null, b: string | null) => {
56+
if (typeof a === 'string' && typeof b === 'string')
57+
return a.normalize() !== b.normalize()
58+
return a !== b
59+
}
60+
return compare(notEqual, inputValue, value, 'some')
61+
}
4662
const notContains = (a: string | null, b: string | null) => {
4763
if (b === '' || !b || !a) return true
4864
return !a

0 commit comments

Comments
 (0)