From a8d025395bc0032d964c2afc8c4fb5d2fa631a44 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 20 Jun 2023 20:55:18 +0200 Subject: [PATCH] Link: Fix protocol verification (#3417) --- src/util/ensureProtocol.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util/ensureProtocol.ts b/src/util/ensureProtocol.ts index 412ad9fcf..f32c5bbf8 100644 --- a/src/util/ensureProtocol.ts +++ b/src/util/ensureProtocol.ts @@ -5,5 +5,15 @@ export function ensureProtocol(url?: string) { // HTTP was chosen by default as a fix for https://bugs.telegram.org/c/10712. // It is also the default protocol in the official TDesktop client. - return url.includes('://') ? url : `http://${url}`; + try { + const parsedUrl = new URL(url); + // eslint-disable-next-line no-script-url + if (parsedUrl.protocol === 'javascript:') { + return `http://${url}`; + } + + return url; + } catch (err) { + return `http://${url}`; + } }