fix: handle underscores in project path generation

Add underscore to the regex pattern in getProjectPath to ensure underscores
are replaced with hyphens, along with existing handling for slashes, colons,
and dots. Includes test case for paths with underscores.
This commit is contained in:
weishu
2025-12-17 20:00:35 +08:00
parent a6d088b51d
commit 1b99c9422b
2 changed files with 7 additions and 1 deletions
+6
View File
@@ -38,6 +38,12 @@ describe('getProjectPath', () => {
expect(result).toBe(join('/home/user', '.claude', 'projects', '-var-www-my-site-com-public')); expect(result).toBe(join('/home/user', '.claude', 'projects', '-var-www-my-site-com-public'));
}); });
it('should replace underscores with hyphens in the project path', () => {
const workingDir = '/data/github/hapi__worktrees/ime';
const result = getProjectPath(workingDir);
expect(result).toBe(join('/home/user', '.claude', 'projects', '-data-github-hapi--worktrees-ime'));
});
it('should handle relative paths by resolving them first', () => { it('should handle relative paths by resolving them first', () => {
const workingDir = './my-project'; const workingDir = './my-project';
const result = getProjectPath(workingDir); const result = getProjectPath(workingDir);
+1 -1
View File
@@ -2,7 +2,7 @@ import { homedir } from "node:os";
import { join, resolve } from "node:path"; import { join, resolve } from "node:path";
export function getProjectPath(workingDirectory: string) { export function getProjectPath(workingDirectory: string) {
const projectId = resolve(workingDirectory).replace(/[\\\/\.:]/g, '-'); const projectId = resolve(workingDirectory).replace(/[\\\/\.:_]/g, '-');
const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude'); const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude');
return join(claudeConfigDir, 'projects', projectId); return join(claudeConfigDir, 'projects', projectId);
} }