Browse Source

fix(api): encode file path in `convertFileSrc` function, closes #3841 (#3846)

Lucas Fernandes Nogueira 3 năm trước cách đây
mục cha
commit
42e8d9cf92
2 tập tin đã thay đổi với 8 bổ sung2 xóa
  1. 5 0
      .changes/api-encode-protocol-path.md
  2. 3 2
      tooling/api/src/tauri.ts

+ 5 - 0
.changes/api-encode-protocol-path.md

@@ -0,0 +1,5 @@
+---
+"api": patch
+---
+
+Encode the file path in the `convertFileSrc` function.

+ 3 - 2
tooling/api/src/tauri.ts

@@ -114,9 +114,10 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
  * @return the URL that can be used as source on the webview.
  */
 function convertFileSrc(filePath: string, protocol = 'asset'): string {
+  const path = encodeURIComponent(filePath)
   return navigator.userAgent.includes('Windows')
-    ? `https://${protocol}.localhost/${filePath}`
-    : `${protocol}://${filePath}`
+    ? `https://${protocol}.localhost/${path}`
+    : `${protocol}://${path}`
 }
 
 export type { InvokeArgs }