diff --git a/src/utils/url.test.ts b/src/utils/url.test.ts index 621c4d90e..f1570bb14 100644 --- a/src/utils/url.test.ts +++ b/src/utils/url.test.ts @@ -152,6 +152,8 @@ describe('url', () => { expect(mergePath('/book', 'hey', 'say')).toBe('/book/hey/say') expect(mergePath('/book', '/hey/', '/say/')).toBe('/book/hey/say/') expect(mergePath('/book', '/hey/', '/say/', '/')).toBe('/book/hey/say/') + expect(mergePath('/book', '/hey', '/say', '/')).toBe('/book/hey/say') + expect(mergePath('/', '/book', '/hey', '/say', '/')).toBe('/book/hey/say') expect(mergePath('book', '/')).toBe('/book') expect(mergePath('book/', '/')).toBe('/book/') diff --git a/src/utils/url.ts b/src/utils/url.ts index 7c87846a2..eea5b4483 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -141,10 +141,12 @@ export const mergePath = (...paths: string[]): string => { let endsWithSlash = false for (let path of paths) { + // calculate endsWithSlash at the start of each iteration + endsWithSlash = p.at(-1) === '/' + /* ['/hey/','/say'] => ['/hey', '/say'] */ - if (p.at(-1) === '/') { + if (endsWithSlash) { p = p.slice(0, -1) - endsWithSlash = true } /* ['/hey','say'] => ['/hey', '/say'] */