From 86cb8cac67bc69a63a61a1622499770288db6842 Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Mon, 1 Feb 2021 13:47:31 +0530 Subject: [PATCH] Allow for navigateTo urls to be of `mailto` or `tel` url schemes t (#2781) --- app/client/src/sagas/ActionExecutionSagas.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/client/src/sagas/ActionExecutionSagas.ts b/app/client/src/sagas/ActionExecutionSagas.ts index cc9436c698..279cfa4c8e 100644 --- a/app/client/src/sagas/ActionExecutionSagas.ts +++ b/app/client/src/sagas/ActionExecutionSagas.ts @@ -92,6 +92,19 @@ export enum NavigationTargetType { NEW_WINDOW = "NEW_WINDOW", } +const isValidUrlScheme = (url: string): boolean => { + return ( + // Standard http call + url.startsWith("http://") || + // Secure http call + url.startsWith("https://") || + // Mail url to directly open email app prefilled + url.startsWith("mailto:") || + // Tel url to directly open phone app prefilled + url.startsWith("tel:") + ); +}; + function* navigateActionSaga( action: { pageNameOrUrl: string; @@ -131,9 +144,9 @@ function* navigateActionSaga( AnalyticsUtil.logEvent("NAVIGATE", { navUrl: pageNameOrUrl, }); - // Add a default protocol if it doesn't exist. let url = pageNameOrUrl + convertToQueryParams(params); - if (url.indexOf("://") === -1) { + // Add a default protocol if it doesn't exist. + if (!isValidUrlScheme(url)) { url = "https://" + url; } if (target === NavigationTargetType.SAME_WINDOW) {