diff --git a/frontend/src/utils/formatPath.test.ts b/frontend/src/utils/formatPath.test.ts index 63b4668c98b..aa64ea7367b 100644 --- a/frontend/src/utils/formatPath.test.ts +++ b/frontend/src/utils/formatPath.test.ts @@ -28,6 +28,7 @@ test('formatAssetPath', () => { expect(formatAssetPath('/a', '/x')).toEqual('/x/a'); expect(formatAssetPath('/a/', '/x/')).toEqual('/x/a'); expect(formatAssetPath('a/b/', 'x/y/')).toEqual('/x/y/a/b'); + expect(formatAssetPath('x/y/', 'x/y/')).toEqual('/x/y'); expect(formatAssetPath('//a//b//', '//x//y//')).toEqual('/x/y/a/b'); }); @@ -42,6 +43,7 @@ test('formatApiPath', () => { expect(formatApiPath('/', '/')).toEqual(''); expect(formatApiPath('a', 'x')).toEqual('/x/a'); expect(formatApiPath('/a', '/x')).toEqual('/x/a'); + expect(formatApiPath('/a', '/x/a')).toEqual('/x/a'); expect(formatApiPath('/a/', '/x/')).toEqual('/x/a'); expect(formatApiPath('a/b/', 'x/y/')).toEqual('/x/y/a/b'); expect(formatApiPath('//a//b//', '//x//y//')).toEqual('/x/y/a/b'); diff --git a/frontend/src/utils/formatPath.ts b/frontend/src/utils/formatPath.ts index fed18ba1818..62f94ec852d 100644 --- a/frontend/src/utils/formatPath.ts +++ b/frontend/src/utils/formatPath.ts @@ -23,7 +23,14 @@ export const parseBasePath = (value = basePathMetaTagContent()): string => { // Join paths with a leading separator and without a trailing separator. const joinPaths = (...paths: string[]): string => { - return ['', ...paths] + const filteredPaths = paths.filter(path => { + return !paths.some( + currentPath => currentPath !== path && currentPath.includes(path) + ); + }); + const uniquePaths = [...new Set(filteredPaths)]; + + return ['', ...uniquePaths] .join('/') .replace(/\/+$/g, '') // Remove trailing separators. .replace(/\/+/g, '/'); // Collapse repeated separators.