Skip to content

Commit

Permalink
fix(joinURL): don't allow double '//' when single slashes are passed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Feb 8, 2021
1 parent bb2a64a commit e44fe2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export function joinURL (base: string, ...input: string[]): string {
let url = base || ''

for (const i of input) {
url = withTrailingSlash(url) + withoutLeadingSlash(i)
const part = withoutLeadingSlash(i)
if (part !== '/') {
url = withTrailingSlash(url) + part
}
}

return url
Expand Down
1 change: 1 addition & 0 deletions test/join.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('joinURL', () => {
{ input: ['/'], out: '/' },
{ input: ['/a'], out: '/a' },
{ input: ['a', 'b'], out: 'a/b' },
{ input: ['/', '/b'], out: '/b' },
{ input: ['a', 'b/', 'c'], out: 'a/b/c' },
{ input: ['a', 'b/', '/c'], out: 'a/b/c' }
]
Expand Down

0 comments on commit e44fe2b

Please sign in to comment.