diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/url-helpers.ts | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts index ef2805595..1eda325da 100644 --- a/src/helpers/url-helpers.ts +++ b/src/helpers/url-helpers.ts | |||
@@ -15,9 +15,6 @@ export function isValidExternalURL(url: string | URL) { | |||
15 | } catch { | 15 | } catch { |
16 | return false; | 16 | return false; |
17 | } | 17 | } |
18 | if (url.toString().endsWith('/')) { | ||
19 | return false; | ||
20 | } | ||
21 | 18 | ||
22 | const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); | 19 | const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); |
23 | 20 | ||
@@ -26,6 +23,10 @@ export function isValidExternalURL(url: string | URL) { | |||
26 | return isAllowed; | 23 | return isAllowed; |
27 | } | 24 | } |
28 | 25 | ||
26 | export function fixUrl(url: string | URL) { | ||
27 | return url.toString().replaceAll('//', '/').replace('http:/', 'http://').replace('https:/', 'https://').replace('file:/', 'file://'); | ||
28 | } | ||
29 | |||
29 | export function isValidFileUrl(path: string) { | 30 | export function isValidFileUrl(path: string) { |
30 | return path.startsWith('file') && existsSync(new URL(path)); | 31 | return path.startsWith('file') && existsSync(new URL(path)); |
31 | } | 32 | } |
@@ -40,8 +41,9 @@ export function openExternalUrl( | |||
40 | url: string | URL, | 41 | url: string | URL, |
41 | skipValidityCheck: boolean = false, | 42 | skipValidityCheck: boolean = false, |
42 | ) { | 43 | ) { |
43 | debug('Open url:', url, 'with skipValidityCheck:', skipValidityCheck); | 44 | const fixedUrl = fixUrl(url.toString()); |
44 | if (skipValidityCheck || isValidExternalURL(url)) { | 45 | debug('Open url:', fixedUrl, 'with skipValidityCheck:', skipValidityCheck); |
45 | shell.openExternal(url.toString()); | 46 | if (skipValidityCheck || isValidExternalURL(fixedUrl)) { |
47 | shell.openExternal(fixedUrl.toString()); | ||
46 | } | 48 | } |
47 | } | 49 | } |