Repository: unjs/ufo (ts)

Issue:
override urls with protocol with `withBase`
Reference: https://github.com/unjs/ohmyfetch/pull/113

Current behavior:

```js
// http://base/http://domain
ufo.withBase('http://domain', 'http://base')
```

New behavior:

```js
// http://domain
ufo.withBase('http://domain', 'http://base'})
```

URL behavior:

```js
// http://domain/
new URL('http://domain', 'http://base').toString()
```


Pull request description:
fix: ensure `withBase` does not prefix URLs with protocol
resolves #67

Patch:
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)


Test patch:
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) {