Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(search): treat types "" and whitespace-only strings as no filter (#5390)
garrytan7361a3089ceb
diff --git a/src/core/ops/search.ts b/src/core/ops/search.tsindex 1d0f859abf..c671dc6a3a 100644--- a/src/core/ops/search.ts+++ b/src/core/ops/search.ts@@ -248,7 +248,8 @@ async function buildRetrievalResponseMeta(* and a non-empty list whose entries trim/filter to nothing loudly* (invalid_params) instead of silently dropping the filter.*- * #5390: a structurally empty array (`[]`) carries no user intent — it is+ * #5390: a structurally empty array (`[]`), `""` or a whitespace-only string+ * carries no user intent — it is* what OpenAI-family MCP clients send when an LLM over-fills every optional* parameter with a type-zero value. Treat it as absent (no filter applied)* rather than throwing, so the search still runs unfiltered. A non-empty@@ -259,9 +260,11 @@ async function buildRetrievalResponseMeta(*/function normalizeTypesParam(raw: unknown): string[] | undefined {if (raw === undefined || raw === null) return undefined;- // #5390: structurally empty array is treated as absent, not as a request- // for an impossible filter. The CLI typo guard below still catches `',,'`.+ // #5390: a structurally empty array, an empty string or a whitespace-only+ // string is treated as absent, not as a request for an impossible filter.+ // The CLI typo guard below still catches `',,'`, `' , '` and `['']`.if (Array.isArray(raw) && raw.length === 0) return undefined;+ if (typeof raw === 'string' && raw.trim() === '') return undefined;const arr = Array.isArray(raw)? raw: typeof raw === 'string'diff --git a/test/ops-search-types.test.ts b/test/ops-search-types.test.tsindex 183f1fe220..51ee3cba0d 100644--- a/test/ops-search-types.test.ts+++ b/test/ops-search-types.test.ts@@ -109,6 +109,23 @@ describe('search op — types param (#3985)', () => {searchOp.handler(ctxOf(), { query: 'zebra telescope', types: [''] }),).rejects.toThrow(/no usable page-type/i);});++ test('empty and whitespace-only strings are treated as no filter (#5390)', async () => {+ for (const types of ['', ' ']) {+ const out = await searchOp.handler(ctxOf(), { query: 'zebra telescope', types });+ expect(slugsOf(out)).toEqual([+ 'companies/acme-example',+ 'notes/telescope-note',+ 'people/alice-example',+ ]);+ }+ });++ test('a comma-only string still rejects as invalid_params (#5390)', async () => {+ await expect(+ searchOp.handler(ctxOf(), { query: 'zebra telescope', types: ',,' }),+ ).rejects.toThrow(/no usable page-type/i);+ });});describe('query op — types param (#3985)', () => {@@ -135,4 +152,16 @@ describe('query op — types param (#3985)', () => {queryOp.handler(ctxOf(), { query: 'zebra telescope', types: { person: true } }),).rejects.toThrow(/types.*must be an array/i);});++ test('types: [], "" and " " run unfiltered; [\'\'] still rejects (#5390)', async () => {+ await withEnv({ OPENAI_API_KEY: undefined }, async () => {+ for (const types of [[], '', ' ']) {+ const out = await queryOp.handler(ctxOf(), { query: 'zebra telescope', expand: false, types });+ expect(slugsOf(out)).toEqual(['companies/acme-example', 'notes/telescope-note', 'people/alice-example']);+ }+ await expect(+ queryOp.handler(ctxOf(), { query: 'zebra telescope', expand: false, types: [''] }),+ ).rejects.toThrow(/no usable page-type/i);+ });+ });});