Skip to content

Commit 485c0d2

Browse files
committed
fix: URL as APINamespace
when URL is used as APINamespace, one slash is missing due to uri.join from unity-utils dropping consecutive slashes
1 parent 222487f commit 485c0d2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/callAPIMethod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export function getAPIPrefix(APINamespace) {
1919
return reAbsolute.test(APINamespace) ? APINamespace : '/' + APINamespace;
2020
}
2121

22-
function getFullPath(APINamespace, namespace, path=[]) {
22+
export function getFullPath(APINamespace, namespace, path=[]) {
2323
path = [].concat(path);
24-
return uri.join(getAPIPrefix(APINamespace), namespace, ...path);
24+
return uri.join(getAPIPrefix(APINamespace), namespace, ...path).replace(':/', '://');
2525
}
2626

2727
function callAPI(APINamespace, fetchOptions, namespace = '', { path=[], query={}, options={}, method='json' }) {

test/callAPIMethod.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import test from 'ava';
2-
import { getAPIPrefix } from '../src/callAPIMethod';
2+
import { getAPIPrefix, getFullPath } from '../src/callAPIMethod';
33

44
test('getAPIPrefix', t => {
55
t.is(getAPIPrefix('api'), '/api', 'relative path');
66
t.is(getAPIPrefix('/api'), '/api', 'absolute path');
77
t.is(getAPIPrefix('http://api.example.com'), 'http://api.example.com', 'http url');
88
t.is(getAPIPrefix('https://api.example.com'), 'https://api.example.com', 'http url');
99
t.is(getAPIPrefix('//api.example.com'), '//api.example.com', 'protocol-less url');
10+
t.is(getAPIPrefix('https://localhost:8080'), 'https://localhost:8080', 'localhost');
11+
});
12+
13+
test('getFullPath', t => {
14+
t.is(getFullPath('api'), '/api', 'relative path');
15+
t.is(getFullPath('/api'), '/api', 'absolute path');
16+
t.is(getFullPath('http://example.com', '/test'), 'http://example.com/test', 'url');
17+
t.is(getFullPath('http://example.com///', '/test/'), 'http://example.com/test/', 'url with slashes');
18+
t.is(getFullPath('https://localhost:8080', '/test///'), 'https://localhost:8080/test/', 'localhost');
1019
});

0 commit comments

Comments
 (0)