Expand Windows-style tilde paths
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s

This commit is contained in:
DuProcess
2026-07-16 20:04:57 -04:00
parent 6cb8f50205
commit 77caebf310
+25 -2
View File
@@ -325,9 +325,17 @@ pub fn load_hosts_config(path: Option<PathBuf>) -> Result<HostsConfig> {
} }
pub fn expand_tilde(path: &str) -> PathBuf { pub fn expand_tilde(path: &str) -> PathBuf {
if let Some(rest) = path.strip_prefix("~/") let rest = if path == "~" {
Some("")
} else {
path.strip_prefix("~/").or_else(|| path.strip_prefix("~\\"))
};
if let Some(rest) = rest
&& let Some(home) = dirs::home_dir() && let Some(home) = dirs::home_dir()
{ {
if rest.is_empty() {
return home;
}
return home.join(rest); return home.join(rest);
} }
PathBuf::from(path) PathBuf::from(path)
@@ -335,7 +343,8 @@ pub fn expand_tilde(path: &str) -> PathBuf {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{ClientConfig, ServerConfig}; use super::{ClientConfig, ServerConfig, expand_tilde};
use std::path::PathBuf;
#[test] #[test]
fn old_client_configs_fill_new_fields_from_defaults() { fn old_client_configs_fill_new_fields_from_defaults() {
@@ -360,6 +369,20 @@ dosh_port = 50000
assert!(config.send_env.iter().any(|value| value == "TERM")); assert!(config.send_env.iter().any(|value| value == "TERM"));
} }
#[test]
fn expand_tilde_handles_unix_and_windows_separators() {
let Some(home) = dirs::home_dir() else {
return;
};
assert_eq!(expand_tilde("~"), home);
assert_eq!(expand_tilde("~/one/two"), home.join("one/two"));
assert_eq!(expand_tilde("~\\one\\two"), home.join("one\\two"));
assert_eq!(
expand_tilde("relative/path"),
PathBuf::from("relative/path")
);
}
#[test] #[test]
fn old_server_configs_fill_new_fields_from_defaults() { fn old_server_configs_fill_new_fields_from_defaults() {
let raw = r#" let raw = r#"