From cbf73937c0c24de2f26112478657ad21dfe031f5 Mon Sep 17 00:00:00 2001 From: itolstov Date: Wed, 15 Jul 2026 06:48:22 -0300 Subject: [PATCH] fix(combos): drop nullish entries in filterActiveConnections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `connection?.isActive !== false` evaluated to true for null/undefined entries, so nullish elements survived the filter. Callers read properties off the result — filterUsableConnections() reads `connection.testStatus` — which would throw "TypeError: Cannot read properties of null". Guard with an explicit truthiness check. Covered by a test that fails against the previous predicate. Reported-by: gemini-code-assist Co-authored-by: diegosouzapw --- src/shared/utils/connectionStatus.ts | 5 +++-- .../connection-status-filter-active-2526.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/shared/utils/connectionStatus.ts b/src/shared/utils/connectionStatus.ts index a2a4ff1446..4a6baaf4de 100644 --- a/src/shared/utils/connectionStatus.ts +++ b/src/shared/utils/connectionStatus.ts @@ -16,13 +16,14 @@ export interface ConnectionActiveFlag { /** * Filters out connections that have been explicitly disabled * (`isActive === false`). Connections without an `isActive` field are - * treated as active for backward compatibility. + * treated as active for backward compatibility. Nullish entries are + * dropped so callers can safely read properties off the result. */ export function filterActiveConnections( connections: T[] | null | undefined ): T[] { if (!Array.isArray(connections)) return []; - return connections.filter((connection) => connection?.isActive !== false); + return connections.filter((connection) => !!connection && connection.isActive !== false); } /** diff --git a/tests/unit/connection-status-filter-active-2526.test.ts b/tests/unit/connection-status-filter-active-2526.test.ts index ff0e5eb2e3..9e60485fc3 100644 --- a/tests/unit/connection-status-filter-active-2526.test.ts +++ b/tests/unit/connection-status-filter-active-2526.test.ts @@ -25,6 +25,18 @@ test("filterActiveConnections returns an empty list for invalid input", () => { assert.deepEqual(filterActiveConnections(null), []); }); +test("filterActiveConnections drops nullish entries instead of passing them through", () => { + // A nullish element must not survive: callers read properties off the + // result (e.g. `connection.testStatus`) and would throw a TypeError. + const active = { id: "active", isActive: true }; + + assert.deepEqual(filterActiveConnections([null, active, undefined]), [active]); + assert.doesNotThrow(() => filterUsableConnections([null, undefined])); + assert.deepEqual(filterUsableConnections([null, { id: "ok", testStatus: "active" }]), [ + { id: "ok", testStatus: "active" }, + ]); +}); + test("filterUsableConnections applies the isActive gate before the testStatus gate", () => { // Regression for the exact bug: a disabled connection with a stale // "active" testStatus must NOT survive the combined filter that