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 === '' ||