Skip to content

Commit

Permalink
fix: ensure withBase does not prefix URLs with protocol (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jul 29, 2022
1 parent 67a1c6f commit b520298
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/utils.ts
Expand Up @@ -62,7 +62,7 @@ export function cleanDoubleSlashes (input: string = ''): string {
}

export function withBase (input: string, base: string) {
if (isEmptyURL(base)) {
if (isEmptyURL(base) || hasProtocol(input)) {
return input
}
const _base = withoutTrailingSlash(base)
Expand Down
8 changes: 6 additions & 2 deletions test/base.test.ts
Expand Up @@ -10,7 +10,9 @@ describe('withBase', () => {
{ base: '/base/', input: '/base', out: '/base' },
{ base: '/base', input: '/base/', out: '/base/' },
{ base: '/base', input: '/base/a', out: '/base/a' },
{ base: '/base/', input: '/base/a', out: '/base/a' }
{ base: '/base/', input: '/base/a', out: '/base/a' },
{ base: '/base/', input: 'https://test.com', out: 'https://test.com' },
{ base: '/', input: 'https://test.com', out: 'https://test.com' }
]

for (const t of tests) {
Expand All @@ -33,7 +35,9 @@ describe('withoutBase', () => {
{ base: '/base/a/', input: '/base/a', out: '/' },
{ base: '/', input: '/test/', out: '/test/' },
{ base: '/', input: '/?test', out: '/?test' },
{ base: '/api', input: '/api?test', out: '/?test' }
{ base: '/api', input: '/api?test', out: '/?test' },
{ base: '/base/', input: 'https://test.com', out: 'https://test.com' },
{ base: '/', input: 'https://test.com', out: 'https://test.com' }
]

for (const t of tests) {
Expand Down

0 comments on commit b520298

Please sign in to comment.