Skip to content
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
5 changes: 5 additions & 0 deletions packages/bot/__tests__/units/methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,9 @@ test('addKeyword debe rechazar array vacío', () => {
assert.throws(() => addKeyword([] as any), /empty/i)
})

test('addKeyword debe rechazar strings vacíos dentro del array', () => {
assert.throws(() => addKeyword(['']), /empty/i)
assert.throws(() => addKeyword(['hola', '']), /empty/i)
})

test.run()
6 changes: 2 additions & 4 deletions packages/bot/src/io/methods/addKeyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ const addKeyword = <P = any, B = any>(
throw new Error('DEBE_SER_STRING_ARRAY_REGEX')
}

// Un keyword vacío nunca puede matchear nada: casi siempre es un error de
// configuración (p. ej. una env var sin definir). Fallamos rápido en lugar
// de registrar un flow muerto que nunca se dispara.
if (keyword.length === 0) {
// Empty entries become match-all regular expressions in FlowClass.
if (keyword.length === 0 || (Array.isArray(keyword) && keyword.some((item) => item.length === 0))) {
throw new Error('KEYWORD_CANNOT_BE_EMPTY')
}

Expand Down