Skip to content

Commit

Permalink
fix: prevent duplicate locale in URL path
Browse files Browse the repository at this point in the history
- Add check for single locale path (e.g., '/en') in getLocalizedPath
- Treat single locale paths same as root path, returning '/{locale}'
- Fixes API call errors caused by malformed URLs with duplicate locales
  • Loading branch information
sunilsabatp committed Jan 13, 2025
1 parent 6546740 commit 2040623
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/utils/projectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,17 @@ export const areMapCoordsEqual = (
export const getLocalizedPath = (path: string, locale: string): string => {
// Strip query parameters if present
const pathWithoutQuery = path.split('?')[0];

// Remove trailing slash if present
const cleanPath = pathWithoutQuery.endsWith('/')
? pathWithoutQuery.slice(0, -1)
: pathWithoutQuery;

// Handle root path special case
if (cleanPath === '' || cleanPath === '/') {
if (cleanPath === '' || cleanPath === '/' || cleanPath === `/${locale}`) {
return `/${locale}`;
}

// If path already starts with locale, return as is
if (cleanPath.startsWith(`/${locale}`)) {
if (cleanPath.startsWith(`/${locale}/`)) {
return cleanPath;
}

Expand Down

0 comments on commit 2040623

Please sign in to comment.