From 7d2e2537cf9cd9f9c1976d5023ae591ef5ba4d0f Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 14 Dec 2022 23:33:32 -0800 Subject: [PATCH] Fix default protocol validation list --- web/pages/admin/actions.tsx | 11 +---------- web/utils/urls.ts | 4 ++-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/web/pages/admin/actions.tsx b/web/pages/admin/actions.tsx index c337feda2..f43061040 100644 --- a/web/pages/admin/actions.tsx +++ b/web/pages/admin/actions.tsx @@ -69,16 +69,7 @@ const ActionModal = (props: Props) => { } function canSave(): Boolean { - try { - const validationObject = new URL(actionUrl); - if (validationObject.protocol !== 'https:') { - return false; - } - } catch { - return false; - } - - return isValidUrl(actionUrl) && actionTitle !== ''; + return isValidUrl(actionUrl, ['https:']) && actionTitle !== ''; } const okButtonProps = { diff --git a/web/utils/urls.ts b/web/utils/urls.ts index fbee5a264..4a64ec971 100644 --- a/web/utils/urls.ts +++ b/web/utils/urls.ts @@ -7,10 +7,10 @@ export const DEFAULT_TEXTFIELD_URL_PATTERN = 'https?://.*'; * @param {string[]} validProtocols - An array of valid protocols. Defaults to web. * @returns {boolean} - True if the URI is valid, false otherwise. */ -export function isValidUrl(url: string, validProtocols: string[] = ['http', 'https']): boolean { - console.log(url, validProtocols); +export function isValidUrl(url: string, validProtocols: string[] = ['http:', 'https:']): boolean { try { const validationObject = new URL(url); + if ( validationObject.protocol === '' || validationObject.hostname === '' ||