ctx-core 5.36.2 → 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.
@@ -8,19 +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
- ~[
13
- '/',
14
- '?',
15
- '&'
16
- ].indexOf(url_segment_str[0])
17
- || (!url && url_segment_str.includes('://'))
18
- ? url_segment_str
19
- : in_query
20
- ? '&' + url_segment_str
21
- : '/' + url_segment_str
13
+ url_segment_str[0] === '/' && last_char === '/'
14
+ ? url_segment_str.slice(1)
15
+ : ~['/', '?', '&'].indexOf(url_segment_str[0])
16
+ || (!url && url_segment_str.includes('://'))
17
+ || in_query && last_char === '&'
18
+ || !in_query && last_char === '/'
19
+ ? url_segment_str
20
+ : in_query
21
+ ? '&' + url_segment_str
22
+ : '/' + url_segment_str
22
23
  )
23
- if (url_segment_str.includes('?')) in_query = 1
24
+ if (!in_query && url_segment_str.includes('?')) in_query = 1
24
25
  }
25
26
  return url
26
27
  }
@@ -23,5 +23,14 @@ test('url__join', ()=>{
23
23
  equal(
24
24
  url__join(['http://localhost/foo/bar/baz?id=1', [['something=else']]]),
25
25
  'http://localhost/foo/bar/baz?id=1&something=else')
26
+ equal(
27
+ url__join(['http://localhost/', '/foo/bar/baz?id=1', 'something=else']),
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')
26
35
  })
27
36
  test.run()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "5.36.2",
3
+ "version": "5.36.4",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",