Browse Source

fix(core): percent decode asset protocol URL (#2427)

Lucas Fernandes Nogueira 4 years ago
parent
commit
9acd83017f
2 changed files with 8 additions and 0 deletions
  1. 5 0
      .changes/percent-decode-asset-protocol.md
  2. 3 0
      core/tauri/src/manager.rs

+ 5 - 0
.changes/percent-decode-asset-protocol.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Use `percent_encoding::percent_decode` on the `asset` custom protocol URL before reading the file.

+ 3 - 0
core/tauri/src/manager.rs

@@ -285,6 +285,9 @@ impl<R: Runtime> WindowManager<R> {
     if !webview_attributes.has_uri_scheme_protocol("asset") {
       webview_attributes = webview_attributes.register_uri_scheme_protocol("asset", move |url| {
         let path = url.replace("asset://", "");
+        let path = percent_encoding::percent_decode(path.as_bytes())
+          .decode_utf8_lossy()
+          .to_string();
         let data = crate::async_runtime::block_on(async move { tokio::fs::read(path).await })?;
         Ok(data)
       });