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:
SRutile
2024-09-11 23:02:24 +08:00
committed by GitHub
parent 3715f3c9a6
commit 9291e4d2ca
6 changed files with 13 additions and 5 deletions
+4 -3
View File
@@ -855,10 +855,11 @@ pub async fn write_file<R: Runtime>(
.get("path")
.ok_or_else(|| anyhow::anyhow!("missing file path").into())
.and_then(|p| {
p.to_str()
.map_err(|e| anyhow::anyhow!("invalid path: {e}").into())
percent_encoding::percent_decode(p.as_ref())
.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
.headers()
.get("options")