diff --git a/src/utils.ts b/src/utils.ts index bb706db..88efeb7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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) diff --git a/test/base.test.ts b/test/base.test.ts index 661471b..3cbd91e 100644 --- a/test/base.test.ts +++ b/test/base.test.ts @@ -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) { @@ -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) {