Skip to content

Commit f1674fc

Browse files
authored
feat(core/windows): Convert UNC paths to simple paths in JS apis. (#9420)
1 parent 73c1c2d commit f1674fc

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

.changes/api-simplify-unc-paths.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri: patch:enhance
3+
---
4+
5+
Tauri's built-in commands for the JS api will now return simplified paths on Windows, removing the `\\?\` prefix.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ http-range = { version = "0.1.5", optional = true }
7373
tracing = { version = "0.1", optional = true }
7474
heck = "0.4"
7575
log = "0.4"
76+
dunce = "1"
7677

7778
[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]
7879
muda = { version = "0.13", default-features = false, features = [ "serde" ] }

core/tauri/src/path/plugin.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn resolve_directory<R: Runtime>(
9292
directory: BaseDirectory,
9393
path: Option<PathBuf>,
9494
) -> Result<PathBuf> {
95-
super::resolve_path(&resolver, directory, path)
95+
super::resolve_path(&resolver, directory, path).map(|p| dunce::simplified(&p).to_path_buf())
9696
}
9797

9898
#[command(root = "crate")]
@@ -107,12 +107,12 @@ pub fn resolve(paths: Vec<String>) -> Result<PathBuf> {
107107
for p in paths {
108108
path.push(p);
109109
}
110-
Ok(normalize_path(&path))
110+
Ok(dunce::simplified(&normalize_path(&path)).to_path_buf())
111111
}
112112

113113
#[command(root = "crate")]
114114
pub fn normalize(path: String) -> String {
115-
let mut p = normalize_path_no_absolute(Path::new(&path))
115+
let mut p = dunce::simplified(&normalize_path_no_absolute(Path::new(&path)))
116116
.to_string_lossy()
117117
.to_string();
118118

@@ -149,9 +149,10 @@ pub fn join(mut paths: Vec<String>) -> String {
149149
.collect::<String>(),
150150
);
151151

152-
let p = normalize_path_no_absolute(&path)
152+
let p = dunce::simplified(&normalize_path_no_absolute(&path))
153153
.to_string_lossy()
154154
.to_string();
155+
155156
if p.is_empty() {
156157
".".into()
157158
} else {
@@ -162,7 +163,7 @@ pub fn join(mut paths: Vec<String>) -> String {
162163
#[command(root = "crate")]
163164
pub fn dirname(path: String) -> Result<PathBuf> {
164165
match Path::new(&path).parent() {
165-
Some(p) => Ok(p.to_path_buf()),
166+
Some(p) => Ok(dunce::simplified(p).to_path_buf()),
166167
None => Err(Error::NoParent),
167168
}
168169
}

0 commit comments

Comments
 (0)