diff --git a/src/utils/url.test.ts b/src/utils/url.test.ts index f1570bb14..621c4d90e 100644 --- a/src/utils/url.test.ts +++ b/src/utils/url.test.ts @@ -152,8 +152,6 @@ 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 eea5b4483..7c87846a2 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -141,12 +141,10 @@ 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 (endsWithSlash) { + if (p.at(-1) === '/') { p = p.slice(0, -1) + endsWithSlash = true } /* ['/hey','say'] => ['/hey', '/say'] */