From 6895d38f71a8f46036762b57f05bd4ca84c95537 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Mon, 10 Jun 2024 20:32:29 +0300 Subject: [PATCH] add leading slash if not present to redirect url --- src/libs/Url.ts | 9 ++++++++- src/libs/actions/Link.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/Url.ts b/src/libs/Url.ts index 69894147a242..970e6b3ed195 100644 --- a/src/libs/Url.ts +++ b/src/libs/Url.ts @@ -11,6 +11,13 @@ function addTrailingForwardSlash(url: string): string { return url; } +function addLeadingForwardSlash(url: string): string { + if (!url.startsWith('/')) { + return `/${url}`; + } + return url; +} + /** * Get path from URL string */ @@ -63,4 +70,4 @@ function hasURL(text: string) { return urlPattern.test(text); } -export {addTrailingForwardSlash, hasSameExpensifyOrigin, getPathFromURL, appendParam, hasURL}; +export {addTrailingForwardSlash, hasSameExpensifyOrigin, getPathFromURL, appendParam, hasURL, addLeadingForwardSlash}; diff --git a/src/libs/actions/Link.ts b/src/libs/actions/Link.ts index 4bc0a61162ae..4b1261dc0872 100644 --- a/src/libs/actions/Link.ts +++ b/src/libs/actions/Link.ts @@ -69,7 +69,7 @@ function openOldDotLink(url: string) { function buildTravelDotURL(spotnanaToken?: string, postLoginPath?: string): Promise { return Promise.all([Environment.getTravelDotEnvironmentURL(), Environment.getSpotnanaEnvironmentTMCID()]).then(([environmentURL, tmcID]) => { const authCode = spotnanaToken ? `authCode=${spotnanaToken}` : ''; - const redirectURL = postLoginPath ? `redirectUrl=${postLoginPath}` : ''; + const redirectURL = postLoginPath ? `redirectUrl=${Url.addLeadingForwardSlash(postLoginPath)}` : ''; const tmcIDParam = `tmcId=${tmcID}`; const paramsArray = [authCode, tmcIDParam, redirectURL];