Skip to content

Commit

Permalink
Ensures there is no unexpected slash in url before query params
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Jul 1, 2022
1 parent 7f76635 commit d33cfee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/toolkit/src/query/tests/utils.test.ts
Expand Up @@ -83,6 +83,15 @@ describe('joinUrls', () => {

expect(joinUrls('', '/banana')).toBe('/banana')
expect(joinUrls('', 'banana')).toBe('banana')

expect(joinUrls('/api', '?a=1')).toBe('/api?a=1')
expect(joinUrls('/api/', '?a=1')).toBe('/api/?a=1')

expect(joinUrls('/api', 'banana?a=1')).toBe('/api/banana?a=1')
expect(joinUrls('/api/', 'banana/?a=1')).toBe('/api/banana/?a=1')

expect(joinUrls('/api', '?a=1')).toBe('/api?a=1')
expect(joinUrls('/api/', '?a=1')).toBe('/api/?a=1')
})

test('correctly joins variations of absolute urls', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/toolkit/src/query/utils/joinUrls.ts
Expand Up @@ -18,8 +18,9 @@ export function joinUrls(
return url
}

const delimiter = base.endsWith('/') || !url.startsWith('?') ? '/' : ''
base = withoutTrailingSlash(base)
url = withoutLeadingSlash(url)

return `${base}/${url}`
return `${base}${delimiter}${url}`;
}

0 comments on commit d33cfee

Please sign in to comment.