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

This commit is contained in:
Lucas Fernandes Nogueira 2022-04-02 07:54:26 -07:00 committed by GitHub
parent b1f83fd05f
commit 42e8d9cf92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

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

View File

@ -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 }