From f4fd7dcfe7b84e54999062325a268d786975ab12 Mon Sep 17 00:00:00 2001 From: Vijay Aravamudhan Date: Sat, 14 May 2022 22:36:26 -0500 Subject: Fix issue where the replacement of double-slash was over-aggressive (#151) --- src/helpers/url-helpers.test.ts | 3 +++ src/helpers/url-helpers.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/helpers') diff --git a/src/helpers/url-helpers.test.ts b/src/helpers/url-helpers.test.ts index 5ea6fa1a8..e6036893e 100644 --- a/src/helpers/url-helpers.test.ts +++ b/src/helpers/url-helpers.test.ts @@ -73,6 +73,9 @@ describe('url_helpers', () => { it('handles string starting with http://', () => { expect(url_helpers.fixUrl('http://some/random/url')).toEqual('http://some/random/url'); expect(url_helpers.fixUrl('http://some//random//url')).toEqual('http://some/random/url'); + + const gmailEmbeddedUrl = 'https://www.google.com/url?q=https://github.com/ferdium/ferdium-app/issues/87&source=gmail'; + expect(url_helpers.fixUrl(gmailEmbeddedUrl)).toEqual(gmailEmbeddedUrl); // it should NOT remove the double-slash from the embedded url in the query string }); it('handles string starting with https://', () => { diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts index 1eda325da..720f242b4 100644 --- a/src/helpers/url-helpers.ts +++ b/src/helpers/url-helpers.ts @@ -24,7 +24,7 @@ export function isValidExternalURL(url: string | URL) { } export function fixUrl(url: string | URL) { - return url.toString().replaceAll('//', '/').replace('http:/', 'http://').replace('https:/', 'https://').replace('file:/', 'file://'); + return url.toString().replaceAll('//', '/').replaceAll('http:/', 'http://').replaceAll('https:/', 'https://').replaceAll('file:/', 'file://'); } export function isValidFileUrl(path: string) { -- cgit v1.2.3-54-g00ecf