diff --git a/packages/bot/__tests__/units/methods.test.ts b/packages/bot/__tests__/units/methods.test.ts index d0da8f4a0..a9b03b147 100644 --- a/packages/bot/__tests__/units/methods.test.ts +++ b/packages/bot/__tests__/units/methods.test.ts @@ -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() diff --git a/packages/bot/src/io/methods/addKeyword.ts b/packages/bot/src/io/methods/addKeyword.ts index 235c63fca..f568a90f0 100644 --- a/packages/bot/src/io/methods/addKeyword.ts +++ b/packages/bot/src/io/methods/addKeyword.ts @@ -25,10 +25,8 @@ const addKeyword =
( 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') }