mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 10:16:49 +00:00
fix(websearch): normalize double-slash paths in hook detection
Add .replace(/\/+/g, '/') to collapse multiple forward slashes, preventing duplicate hook accumulation from malformed paths.
This commit is contained in:
@@ -130,7 +130,9 @@ export function ensureHookConfig(): boolean {
|
||||
const command = hookArray?.[0]?.command;
|
||||
if (typeof command !== 'string') return false;
|
||||
|
||||
const normalized = command.replace(/\\/g, '/');
|
||||
const normalized = command
|
||||
.replace(/\\/g, '/') // Windows backslashes
|
||||
.replace(/\/+/g, '/'); // Collapse multiple slashes
|
||||
return normalized.includes('.ccs/hooks/websearch-transformer');
|
||||
});
|
||||
|
||||
@@ -254,7 +256,9 @@ export function removeHookConfig(): boolean {
|
||||
|
||||
const command = hookArray[0].command as string;
|
||||
// Normalize path separators for cross-platform matching (Windows uses backslashes)
|
||||
const normalizedCommand = command.replace(/\\/g, '/');
|
||||
const normalizedCommand = command
|
||||
.replace(/\\/g, '/') // Windows backslashes
|
||||
.replace(/\/+/g, '/'); // Collapse multiple slashes
|
||||
return !normalizedCommand.includes('.ccs/hooks/websearch-transformer'); // Remove if CCS hook
|
||||
});
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ export function isCcsWebSearchHook(hook: Record<string, unknown>): boolean {
|
||||
if (typeof command !== 'string') return false;
|
||||
|
||||
// Normalize path separators for cross-platform matching
|
||||
const normalizedCommand = command.replace(/\\/g, '/');
|
||||
const normalizedCommand = command
|
||||
.replace(/\\/g, '/') // Windows backslashes
|
||||
.replace(/\/+/g, '/'); // Collapse multiple slashes
|
||||
return normalizedCommand.includes('.ccs/hooks/websearch-transformer');
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,9 @@ function updateHookTimeoutIfNeeded(
|
||||
const command = hookArray[0].command;
|
||||
if (typeof command !== 'string') continue;
|
||||
// Normalize path separators for cross-platform matching (Windows uses backslashes)
|
||||
const normalizedCommand = command.replace(/\\/g, '/');
|
||||
const normalizedCommand = command
|
||||
.replace(/\\/g, '/') // Windows backslashes
|
||||
.replace(/\/+/g, '/'); // Collapse multiple slashes
|
||||
if (!normalizedCommand.includes('.ccs/hooks/websearch-transformer')) continue;
|
||||
|
||||
// Found CCS hook - check if needs update
|
||||
|
||||
@@ -38,6 +38,18 @@ describe('isCcsWebSearchHook', () => {
|
||||
expect(isCcsWebSearchHook(hook)).toBe(true);
|
||||
});
|
||||
|
||||
test('Returns true for path with double slashes (normalization)', () => {
|
||||
const hook = {
|
||||
matcher: 'WebSearch',
|
||||
hooks: [
|
||||
{
|
||||
command: 'node /home/user//.ccs//hooks/websearch-transformer/index.js',
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(isCcsWebSearchHook(hook)).toBe(true);
|
||||
});
|
||||
|
||||
test('Returns false for non-WebSearch matcher', () => {
|
||||
const hook = {
|
||||
matcher: 'SomethingElse',
|
||||
|
||||
Reference in New Issue
Block a user