Skip to content

Commit debac39

Browse files
committed
fix: guard drive-letter fallback with IS_WINDOWS to prevent Unix regression
The fallback path in cwdFromSlug() produced Windows-style `D:/...` paths on Unix for slugs starting with a single letter (e.g. `D-Workspace-...`). Gate the drive-letter fallback behind `IS_WINDOWS` so Unix correctly returns `/D/Workspace/...`. Also fix the test: make the Windows drive-letter fallback assertion Windows-only (itWindows) and add a Unix counterpart asserting the correct `/D/Workspace/project/alpha` result.
1 parent bab2c4f commit debac39

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/__tests__/cwd-from-slug.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ describe('cwdFromSlug', () => {
2121
fs.rmSync(base, { recursive: true, force: true });
2222
});
2323

24-
it('falls back to drive-letter path format when no candidate exists', () => {
24+
itWindows('falls back to drive-letter path format when no candidate exists', () => {
2525
expect(cwdFromSlug('D-Workspace-project-alpha')).toBe('D:/Workspace/project/alpha');
2626
});
2727

28+
it('falls back to Unix path format for drive-letter-like slugs on non-Windows', () => {
29+
if (process.platform === 'win32') return;
30+
expect(cwdFromSlug('D-Workspace-project-alpha')).toBe('/D/Workspace/project/alpha');
31+
});
32+
2833
it('keeps Unix fallback behavior for non-drive slugs', () => {
2934
expect(cwdFromSlug('Users-alice-my-project')).toBe('/Users/alice/my/project');
3035
});

src/utils/slug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function cwdFromSlug(slug: string): string {
6161
resolve(0, []);
6262
if (best) return best;
6363

64-
if (isDriveSlug) {
64+
if (isDriveSlug && IS_WINDOWS) {
6565
const drive = parts[0].toUpperCase();
6666
const rest = parts.slice(1).join('/');
6767
return rest ? `${drive}:/${rest}` : `${drive}:/`;

0 commit comments

Comments
 (0)