From 42e8d9cf925089e9ad591198ee04b0cc0a0eed48 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sat, 2 Apr 2022 07:54:26 -0700 Subject: [PATCH] fix(api): encode file path in `convertFileSrc` function, closes #3841 (#3846) --- .changes/api-encode-protocol-path.md | 5 +++++ tooling/api/src/tauri.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changes/api-encode-protocol-path.md diff --git a/.changes/api-encode-protocol-path.md b/.changes/api-encode-protocol-path.md new file mode 100644 index 000000000..22992adc0 --- /dev/null +++ b/.changes/api-encode-protocol-path.md @@ -0,0 +1,5 @@ +--- +"api": patch +--- + +Encode the file path in the `convertFileSrc` function. diff --git a/tooling/api/src/tauri.ts b/tooling/api/src/tauri.ts index 8b8382c0f..1564a94d5 100644 --- a/tooling/api/src/tauri.ts +++ b/tooling/api/src/tauri.ts @@ -114,9 +114,10 @@ async function invoke(cmd: string, args: InvokeArgs = {}): Promise { * @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 }