mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-20 21:20:42 +02:00
fix(fs): support any UTF-8 path in writeFile (#1640)
* In the `writeFile` function, when `options.baseDir` is not set, convert `path` to URL to avoid errors caused by Chinese characters. * fmt * use TextEncoder * use percent encoding * add change file * fmt --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
co-authored by
Lucas Nogueira
parent
3715f3c9a6
commit
9291e4d2ca
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"fs": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Support any UTF-8 character in the writeFile API.
|
||||||
Generated
+1
@@ -6538,6 +6538,7 @@ dependencies = [
|
|||||||
"glob",
|
"glob",
|
||||||
"notify",
|
"notify",
|
||||||
"notify-debouncer-full",
|
"notify-debouncer-full",
|
||||||
|
"percent-encoding",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ glob = "0.3"
|
|||||||
notify = { version = "6", optional = true, features = ["serde"] }
|
notify = { version = "6", optional = true, features = ["serde"] }
|
||||||
notify-debouncer-full = { version = "0.3", optional = true }
|
notify-debouncer-full = { version = "0.3", optional = true }
|
||||||
dunce = { workspace = true }
|
dunce = { workspace = true }
|
||||||
|
percent-encoding = "2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
watch = ["notify", "notify-debouncer-full"]
|
watch = ["notify", "notify-debouncer-full"]
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1015,7 +1015,7 @@ async function writeFile(
|
|||||||
|
|
||||||
await invoke('plugin:fs|write_file', data, {
|
await invoke('plugin:fs|write_file', data, {
|
||||||
headers: {
|
headers: {
|
||||||
path: path instanceof URL ? path.toString() : path,
|
path: encodeURIComponent(path instanceof URL ? path.toString() : path),
|
||||||
options: JSON.stringify(options)
|
options: JSON.stringify(options)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -855,10 +855,11 @@ pub async fn write_file<R: Runtime>(
|
|||||||
.get("path")
|
.get("path")
|
||||||
.ok_or_else(|| anyhow::anyhow!("missing file path").into())
|
.ok_or_else(|| anyhow::anyhow!("missing file path").into())
|
||||||
.and_then(|p| {
|
.and_then(|p| {
|
||||||
p.to_str()
|
percent_encoding::percent_decode(p.as_ref())
|
||||||
.map_err(|e| anyhow::anyhow!("invalid path: {e}").into())
|
.decode_utf8()
|
||||||
|
.map_err(|_| anyhow::anyhow!("path is not a valid UTF-8").into())
|
||||||
})
|
})
|
||||||
.and_then(|p| SafeFilePath::from_str(p).map_err(CommandError::from))?;
|
.and_then(|p| SafeFilePath::from_str(&p).map_err(CommandError::from))?;
|
||||||
let options = request
|
let options = request
|
||||||
.headers()
|
.headers()
|
||||||
.get("options")
|
.get("options")
|
||||||
|
|||||||
Reference in New Issue
Block a user