summaryrefslogtreecommitdiffstats
path: root/src/helpers
diff options
context:
space:
mode:
authorLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-05-07 13:17:26 -0500
committerLibravatar GitHub <noreply@github.com>2022-05-07 18:17:26 +0000
commita24c037b322dbdc56cbaae3d3fe6f5fa1e819972 (patch)
treedf2125dd4e388c30e5e7a91d02683b86346edfb8 /src/helpers
parentNew Crowdin updates (#118) [skip ci] (diff)
downloadferdium-app-a24c037b322dbdc56cbaae3d3fe6f5fa1e819972.tar.gz
ferdium-app-a24c037b322dbdc56cbaae3d3fe6f5fa1e819972.tar.zst
ferdium-app-a24c037b322dbdc56cbaae3d3fe6f5fa1e819972.zip
New fix for fixing URLs with '//' (#105)
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/url-helpers.ts14
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
26export function fixUrl(url: string | URL) {
27 return url.toString().replaceAll('//', '/').replace('http:/', 'http://').replace('https:/', 'https://').replace('file:/', 'file://');
28}
29
29export function isValidFileUrl(path: string) { 30export 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}