ctx-core 5.36.3 → 5.36.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/all/url__join/index.js
CHANGED
|
@@ -8,17 +8,20 @@ export function url__join(...url_segment_a) {
|
|
|
8
8
|
let in_query = 0
|
|
9
9
|
for (let url_segment of url_segment_a.flat(Infinity)) {
|
|
10
10
|
let url_segment_str = '' + url_segment
|
|
11
|
+
let last_char = url.slice(-1)
|
|
11
12
|
url += (
|
|
12
|
-
url_segment_str[0] === '/' &&
|
|
13
|
+
url_segment_str[0] === '/' && last_char === '/'
|
|
13
14
|
? url_segment_str.slice(1)
|
|
14
15
|
: ~['/', '?', '&'].indexOf(url_segment_str[0])
|
|
15
16
|
|| (!url && url_segment_str.includes('://'))
|
|
17
|
+
|| in_query && last_char === '&'
|
|
18
|
+
|| !in_query && last_char === '/'
|
|
16
19
|
? url_segment_str
|
|
17
20
|
: in_query
|
|
18
21
|
? '&' + url_segment_str
|
|
19
22
|
: '/' + url_segment_str
|
|
20
23
|
)
|
|
21
|
-
if (url_segment_str.includes('?')) in_query = 1
|
|
24
|
+
if (!in_query && url_segment_str.includes('?')) in_query = 1
|
|
22
25
|
}
|
|
23
26
|
return url
|
|
24
27
|
}
|
|
@@ -26,5 +26,11 @@ test('url__join', ()=>{
|
|
|
26
26
|
equal(
|
|
27
27
|
url__join(['http://localhost/', '/foo/bar/baz?id=1', 'something=else']),
|
|
28
28
|
'http://localhost/foo/bar/baz?id=1&something=else')
|
|
29
|
+
equal(
|
|
30
|
+
url__join('http://localhost/', 'foo', 'bar'),
|
|
31
|
+
'http://localhost/foo/bar')
|
|
32
|
+
equal(
|
|
33
|
+
url__join('http://localhost/', '/foo/bar/baz?id=1&', 'something=else'),
|
|
34
|
+
'http://localhost/foo/bar/baz?id=1&something=else')
|
|
29
35
|
})
|
|
30
36
|
test.run()
|