fix: allow dot-prefixed nested worktree paths (#3677)

This commit is contained in:
Neil
2026-05-30 12:19:05 -07:00
committed by GitHub
parent 7d1257f8ee
commit f5d00526e8
2 changed files with 8 additions and 2 deletions
+6
View File
@@ -111,6 +111,12 @@ describe('ensurePathWithinWorkspace', () => {
'Invalid worktree path'
)
})
it('allows workspace children whose names start with dot-dot text', () => {
const result = ensurePathWithinWorkspace('/workspace/..repo/feature', '/workspace')
expect(result).toBe(resolve('/workspace/..repo/feature'))
})
})
describe('computeBranchName', () => {
+2 -2
View File
@@ -1,4 +1,4 @@
import { basename, join, resolve, relative, isAbsolute, posix, win32 } from 'path'
import { basename, join, resolve, relative, isAbsolute, posix, sep, win32 } from 'path'
import type { GitWorktreeInfo, Worktree, WorktreeMeta } from '../../shared/types'
import { splitWorktreeId } from '../../shared/worktree-id'
import { DEFAULT_WORKSPACE_STATUS_ID } from '../../shared/workspace-statuses'
@@ -57,7 +57,7 @@ export function ensurePathWithinWorkspace(targetPath: string, workspaceDir: stri
const resolvedTargetPath = resolve(targetPath)
const rel = relative(resolvedWorkspaceDir, resolvedTargetPath)
if (isAbsolute(rel) || rel.startsWith('..')) {
if (isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`)) {
throw new Error('Invalid worktree path')
}