Link: Fix protocol verification (#3417)

This commit is contained in:
Alexander Zinchuk 2023-06-20 20:55:18 +02:00
parent ee85e49f8f
commit a8d025395b

View File

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