Skip to content

Commit

Permalink
fix(api): encode file path in convertFileSrc function, closes #3841 (
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Apr 2, 2022
1 parent b1f83fd commit 42e8d9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/api-encode-protocol-path.md
@@ -0,0 +1,5 @@
---
"api": patch
---

Encode the file path in the `convertFileSrc` function.
5 changes: 3 additions & 2 deletions tooling/api/src/tauri.ts
Expand Up @@ -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 }
Expand Down

0 comments on commit 42e8d9c

Please sign in to comment.