Skip to content

Commit 089223e

Browse files
committed
Restrict path segment matching to queries containing only alphanumeric characters
1 parent d93c34c commit 089223e

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎packages/shared/src/utils/search-paths/search-paths.spec.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ describe('search_paths', () => {
3737
expect(result[0]).toBe('src/routes/HomePage.tsx')
3838
})
3939

40+
it('should not find "src/routes/HomePage.tsx" with query "src-page"', () => {
41+
const result = search_paths({ paths, search_value: 'src-page' })
42+
expect(result).toHaveLength(0)
43+
})
44+
4045
it('should not find "src/routes/HomePage.tsx" with query "pagesrc"', () => {
4146
const result = search_paths({ paths, search_value: 'pagesrc' })
4247
expect(result).toHaveLength(0)

‎packages/shared/src/utils/search-paths/search-paths.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ export const search_paths = (params: {
8383
return true
8484
}
8585

86-
const query_alphanumeric = search_lower.replace(/[^a-z0-9]/g, '')
87-
if (!query_alphanumeric) {
86+
if (/[^a-z0-9]/.test(search_lower)) {
8887
return false
8988
}
9089

9190
const parts = get_path_parts(path_item)
9291
return is_prefix_match_recursive({
93-
query: query_alphanumeric,
92+
query: search_lower,
9493
parts,
9594
part_idx: 0,
9695
memo: {}

0 commit comments

Comments
 (0)