Skip to content

Commit

Permalink
Merge pull request #2465 from ygrishajev/feature/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Jun 29, 2022
2 parents b01916c + a2e2e79 commit b3d4d89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/toolkit/src/query/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ describe('joinUrls', () => {

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

expect(joinUrls('/api', '?foo=bar')).toBe('/api?foo=bar')
})

test('correctly joins variations of absolute urls', () => {
Expand All @@ -99,6 +101,10 @@ describe('joinUrls', () => {
expect(joinUrls('https://example.com/api/', '/banana/')).toBe(
'https://example.com/api/banana/'
)

expect(joinUrls('https://example.com/api/', '?foo=bar')).toBe(
'https://example.com/api?foo=bar'
)
})
})

Expand Down
3 changes: 2 additions & 1 deletion packages/toolkit/src/query/utils/joinUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function joinUrls(

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

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

0 comments on commit b3d4d89

Please sign in to comment.