From 9701de354f5b0e3a86e10841a8e929367b9b828a Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Mon, 30 Mar 2026 09:45:42 +0800 Subject: [PATCH] fix(terminal): preserve cwd path and strip Windows verbatim prefix - Stop trimming non-empty paths so directories with leading/trailing spaces on Unix are handled correctly - Strip \\?\ extended-length prefix from canonicalized paths on Windows to prevent batch script cd failures --- src-tauri/src/commands/misc.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/commands/misc.rs b/src-tauri/src/commands/misc.rs index aa77fde0f..7e3337dcb 100644 --- a/src-tauri/src/commands/misc.rs +++ b/src-tauri/src/commands/misc.rs @@ -795,10 +795,7 @@ fn extract_env_vars_from_config( } fn resolve_launch_cwd(cwd: Option) -> Result, String> { - let Some(raw_path) = cwd - .map(|value| value.trim().to_string()) - .filter(|value| !value.is_empty()) - else { + let Some(raw_path) = cwd.filter(|value| !value.trim().is_empty()) else { return Ok(None); }; @@ -816,6 +813,18 @@ fn resolve_launch_cwd(cwd: Option) -> Result, String> { return Err(format!("选择的路径不是文件夹: {}", resolved.display())); } + // Strip Windows extended-length prefix (\\?\) that canonicalize produces, + // as it can break batch scripts and other shell commands. + #[cfg(target_os = "windows")] + let resolved = { + let s = resolved.to_string_lossy(); + if let Some(stripped) = s.strip_prefix(r"\\?\") { + PathBuf::from(stripped) + } else { + resolved + } + }; + Ok(Some(resolved)) }