Skip to content

Commit 35f251f

Browse files
committed
🤖 fix: strip trailing slashes from project paths
Fixes #1063 Project paths with trailing slashes (e.g. '/home/user/project/') caused mangled workspace names because basename('/path/') returns an empty string. The fix strips trailing slashes in validateProjectPath(), which is the central validation point for all project paths.
1 parent 5ac2a94 commit 35f251f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/node/utils/pathUtils.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,23 @@ describe("pathUtils", () => {
129129
expect(result.valid).toBe(true);
130130
expect(result.expandedPath).toBe(tempDir);
131131
});
132+
133+
it("should strip trailing slashes from path", async () => {
134+
// Create .git directory for validation
135+
// eslint-disable-next-line local/no-sync-fs-methods -- Test setup only
136+
fs.mkdirSync(path.join(tempDir, ".git"));
137+
138+
// Test with single trailing slash
139+
const resultSingle = await validateProjectPath(`${tempDir}/`);
140+
expect(resultSingle.valid).toBe(true);
141+
expect(resultSingle.expandedPath).toBe(tempDir);
142+
expect(resultSingle.expandedPath).not.toMatch(/[/\\]$/);
143+
144+
// Test with multiple trailing slashes
145+
const resultMultiple = await validateProjectPath(`${tempDir}//`);
146+
expect(resultMultiple.valid).toBe(true);
147+
expect(resultMultiple.expandedPath).toBe(tempDir);
148+
expect(resultMultiple.expandedPath).not.toMatch(/[/\\]$/);
149+
});
132150
});
133151
});

src/node/utils/pathUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ export async function validateProjectPath(inputPath: string): Promise<PathValida
4747
// Expand tilde if present
4848
const expandedPath = expandTilde(inputPath);
4949

50-
// Normalize to resolve any .. or . in the path
51-
const normalizedPath = path.normalize(expandedPath);
50+
// Normalize to resolve any .. or . in the path, then strip trailing slashes
51+
// (path.normalize preserves a single trailing slash which breaks basename extraction)
52+
const normalizedPath = path.normalize(expandedPath).replace(/[/\\]+$/, "");
5253

5354
// Check if path exists
5455
try {

0 commit comments

Comments
 (0)