Skip to content

Commit

Permalink
refactor: handle trailing slash in URL preset
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Jan 19, 2025
1 parent b2b5414 commit 89d721f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/client/src/common/utils/urlPresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export const validateUrlPresetPath = (preset: string): { message: string; isVali
return { isValid: true, message: 'ok' };
};

/**
* Utility removes trailing slash from a string
*/
function removeTrailingSlash(text: string): string {
return text.replace(/\/$/, '');
}

/**
* Gets the URL to send a preset to
* @param location
Expand All @@ -38,7 +45,7 @@ export const getRouteFromPreset = (location: Location, data: URLPreset[], search
const currentURL = location.pathname.substring(1);

// we need to check if the whole url here is an alias, so we can redirect
const foundPreset = data.filter((d) => d.alias === currentURL && d.enabled)[0];
const foundPreset = data.find((preset) => preset.alias === removeTrailingSlash(currentURL) && preset.enabled);
if (foundPreset) {
return generateUrlFromPreset(foundPreset);
}
Expand Down

0 comments on commit 89d721f

Please sign in to comment.