Skip to content

Commit

Permalink
add leading slash if not present to redirect url
Browse files Browse the repository at this point in the history
  • Loading branch information
rushatgabhane committed Jun 10, 2024
1 parent 938b60e commit 6895d38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/libs/Url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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};
2 changes: 1 addition & 1 deletion src/libs/actions/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function openOldDotLink(url: string) {
function buildTravelDotURL(spotnanaToken?: string, postLoginPath?: string): Promise<string> {
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];
Expand Down

0 comments on commit 6895d38

Please sign in to comment.