From f1674fce6dfb1cf0378a85165bb62c270715211b Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Mon, 15 Apr 2024 11:41:31 +0200 Subject: [PATCH] feat(core/windows): Convert UNC paths to simple paths in JS apis. (#9420) --- .changes/api-simplify-unc-paths.md | 5 +++++ Cargo.lock | 1 + core/tauri/Cargo.toml | 1 + core/tauri/src/path/plugin.rs | 11 ++++++----- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changes/api-simplify-unc-paths.md diff --git a/.changes/api-simplify-unc-paths.md b/.changes/api-simplify-unc-paths.md new file mode 100644 index 000000000..f3edca194 --- /dev/null +++ b/.changes/api-simplify-unc-paths.md @@ -0,0 +1,5 @@ +--- +tauri: patch:enhance +--- + +Tauri's built-in commands for the JS api will now return simplified paths on Windows, removing the `\\?\` prefix. diff --git a/Cargo.lock b/Cargo.lock index 20f33b24f..19e6141c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3503,6 +3503,7 @@ dependencies = [ "cocoa", "data-url", "dirs-next", + "dunce", "embed_plist", "futures-util", "getrandom 0.2.12", diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index 52cb69bbc..d8daf4351 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -73,6 +73,7 @@ http-range = { version = "0.1.5", optional = true } tracing = { version = "0.1", optional = true } heck = "0.4" log = "0.4" +dunce = "1" [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"windows\", target_os = \"macos\"))".dependencies] muda = { version = "0.13", default-features = false, features = [ "serde" ] } diff --git a/core/tauri/src/path/plugin.rs b/core/tauri/src/path/plugin.rs index cacd46389..fded281d9 100644 --- a/core/tauri/src/path/plugin.rs +++ b/core/tauri/src/path/plugin.rs @@ -92,7 +92,7 @@ pub fn resolve_directory( directory: BaseDirectory, path: Option, ) -> Result { - super::resolve_path(&resolver, directory, path) + super::resolve_path(&resolver, directory, path).map(|p| dunce::simplified(&p).to_path_buf()) } #[command(root = "crate")] @@ -107,12 +107,12 @@ pub fn resolve(paths: Vec) -> Result { for p in paths { path.push(p); } - Ok(normalize_path(&path)) + Ok(dunce::simplified(&normalize_path(&path)).to_path_buf()) } #[command(root = "crate")] pub fn normalize(path: String) -> String { - let mut p = normalize_path_no_absolute(Path::new(&path)) + let mut p = dunce::simplified(&normalize_path_no_absolute(Path::new(&path))) .to_string_lossy() .to_string(); @@ -149,9 +149,10 @@ pub fn join(mut paths: Vec) -> String { .collect::(), ); - let p = normalize_path_no_absolute(&path) + let p = dunce::simplified(&normalize_path_no_absolute(&path)) .to_string_lossy() .to_string(); + if p.is_empty() { ".".into() } else { @@ -162,7 +163,7 @@ pub fn join(mut paths: Vec) -> String { #[command(root = "crate")] pub fn dirname(path: String) -> Result { match Path::new(&path).parent() { - Some(p) => Ok(p.to_path_buf()), + Some(p) => Ok(dunce::simplified(p).to_path_buf()), None => Err(Error::NoParent), } }