Fix Windows directory cwd prefixes (#6116)

This commit is contained in:
Ricardo Sawir 2026-06-24 03:00:09 +07:00 committed by GitHub
parent 0797966d39
commit ffa80eb5bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -214,6 +214,19 @@ describe('resolveWindowsShellLaunchArgs', () => {
expect(result.validationCwd).toBe('C:\\Users\\alice\\project')
})
it('does not treat MSYS drive cwd as a WSL POSIX cwd', () => {
const result = resolveWindowsShellLaunchArgs(
'wsl.exe',
'/c/Users/alice/project',
'C:\\Users\\alice',
{ distro: 'Ubuntu', treatPosixCwdAsWsl: true }
)
expect(result.shellArgs).toEqual(expectedWslArgs('/mnt/c/Users/alice/project', 'Ubuntu'))
expect(result.effectiveCwd).toBe('C:\\Users\\alice')
expect(result.validationCwd).toBe('C:\\Users\\alice\\project')
})
it('escapes single quotes when translating a WSL cwd', () => {
const result = resolveWindowsShellLaunchArgs('wsl.exe', "C:\\weird'path", 'C:\\Users\\alice')
// The injected sh cmd must not break out of the surrounding single quotes

View File

@ -136,6 +136,7 @@ export function resolveWindowsShellLaunchArgs(
): WindowsShellLaunchArgs {
const shellBasename = pathWin32.basename(shellPath).toLowerCase()
const nativeCwd = normalizeMsysDrivePath(cwd)
const isMsysDriveCwd = nativeCwd !== cwd
if (shellBasename === 'cmd.exe') {
const shellArgStartupCommand = getCmdShellArgStartupCommand(startupCommand)
@ -183,7 +184,7 @@ export function resolveWindowsShellLaunchArgs(
validationCwd: cwd
}
}
if (wslContext?.treatPosixCwdAsWsl && cwd.startsWith('/')) {
if (wslContext?.treatPosixCwdAsWsl && cwd.startsWith('/') && !isMsysDriveCwd) {
return {
shellArgs: buildWslShellArgs(cwd, wslContext.distro),
effectiveCwd: defaultCwd,