From 7ca330c11e89a8b338021e3fcbdd23919fb0dca2 Mon Sep 17 00:00:00 2001 From: Pedro Almeida Date: Tue, 4 Mar 2025 02:42:47 +0000 Subject: [PATCH 1/2] fix: wrong score calculation with trailing white space on search --- cmdk/src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdk/src/index.tsx b/cmdk/src/index.tsx index 86a55a2..6284f19 100644 --- a/cmdk/src/index.tsx +++ b/cmdk/src/index.tsx @@ -358,7 +358,7 @@ const Command = React.forwardRef((props, forwarded function score(value: string, keywords?: string[]) { const filter = propsRef.current?.filter ?? defaultFilter - return value ? filter(value, state.current.search, keywords) : 0 + return value ? filter(value, state.current.search?.trim(), keywords) : 0 } /** Sorts items by score, and groups by highest item score. */ From 361635cfb89e9d479abe470dff667f4ac3549bcd Mon Sep 17 00:00:00 2001 From: Pedro Almeida Date: Wed, 5 Mar 2025 01:47:00 +0000 Subject: [PATCH 2/2] feat: completely sanitize search string --- cmdk/src/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmdk/src/index.tsx b/cmdk/src/index.tsx index 6284f19..04bba83 100644 --- a/cmdk/src/index.tsx +++ b/cmdk/src/index.tsx @@ -358,7 +358,9 @@ const Command = React.forwardRef((props, forwarded function score(value: string, keywords?: string[]) { const filter = propsRef.current?.filter ?? defaultFilter - return value ? filter(value, state.current.search?.trim(), keywords) : 0 + const search = state.current.search ?? '' + const sanitizedSearch = search.replace(/\s+/g, ' ').trim() + return value ? filter(value, sanitizedSearch, keywords) : 0 } /** Sorts items by score, and groups by highest item score. */