drachtio-srf 4.5.33 → 4.5.35

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.
@@ -224,7 +224,9 @@ function parseUri(s) {
224
224
  // eslint-disable-next-line max-len
225
225
  //const re = /^(sips?):(?:([^\s>:@]+)(?::([^\s@>]+))?@)?([\w\-\.]+)(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/;
226
226
  // eslint-disable-next-line max-len
227
- const re = /^(sips?):(?:([^\s>:@]+)(?::([^\s@>]+))?@)?(?:(|(?:\[.*\])|(?:[0-9A-Za-z\-_]+\.)*[0-9A-Za-z\-_]+)|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/;
227
+ // const re = /^(sips?):(?:([^\s>:@]+)(?::([^\s@>]+))?@)?(?:(|(?:\[.*\])|(?:[0-9A-Za-z\-_]+\.)*[0-9A-Za-z\-_]+)|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/;
228
+ // eslint-disable-next-line max-len
229
+ const re = /^(sips?):(?:([^\s@>:]*)(?::([^\s@>]*))?@)?((?:[0-9A-Za-z\-_]+\.)+[0-9A-Za-z\-_]+|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|\[(?:[A-Fa-f0-9:]+)\]|[^@:]*)?(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?([^>]*))?$/;
228
230
  // eslint-disable-next-line max-len
229
231
  //const re = /^(sips?):(?:([^\s>:@]+)(?::([^\s@>]+))?@)?((?:[0-9A-Za-z\-_]+\.)?[0-9A-Za-z\-_]+|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|\[(?:[A-Fa-f0-9:]+)\])(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/;
230
232
 
@@ -241,11 +243,15 @@ function parseUri(s) {
241
243
  port: +r[5],
242
244
  params: (r[6].match(/([^;=]+)(=([^;=]+))?/g) || [])
243
245
  .map(function(s) { return s.split('='); })
244
- .reduce(function(params, x) { params[x[0]] = x[1] || null; return params;}, {}),
245
- headers: ((r[7] || '').match(/[^&=]+=[^&=]+/g) || [])
246
- .map(function(s) { return s.split('='); })
247
- .reduce(function(params, x) { params[x[0]] = x[1]; return params; }, {})
248
- } ;
246
+ .reduce(function(params, x) { params[x[0]] = x[1] || null; return params; }, {}),
247
+ headers: ((r[7] || '').split('&').filter((header) => header !== '').reduce((acc, header) => {
248
+ const index = header.indexOf('=');
249
+ const key = header.slice(0, index);
250
+ const value = header.slice(index + 1);
251
+ acc[key] = value;
252
+ return acc;
253
+ }, {}))
254
+ };
249
255
  } else {
250
256
  // try if this is tel format
251
257
  return parseTelUri(s);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drachtio-srf",
3
- "version": "4.5.33",
3
+ "version": "4.5.35",
4
4
  "description": "drachtio signaling resource framework",
5
5
  "main": "lib/srf.js",
6
6
  "types": "lib/@types/index.d.ts",
package/test/utils.js CHANGED
@@ -7,8 +7,22 @@ process.on('unhandledRejection', (reason, p) => {
7
7
  });
8
8
 
9
9
  test('utils', (t) => {
10
- const uri = Srf.parseUri('sip:1234@10.101.10.1;transport=udp');
10
+ const uri1 = 'sip:1234@10.101.10.1;transport=udp';
11
+ let uri = Srf.parseUri(uri1);
11
12
  t.ok(uri.params.transport === 'udp', 'exposes Srf.parseUri');
13
+ t.ok(Srf.stringifyUri(uri) === uri1, 'exposes Srf.parseUri');
14
+ const uri2 = 'sip:+12345612341t2@sip.jambonz.xyz;param1=value1?User-To-User=XX12344321;encoding=ascii&baba=lala';
15
+ uri = Srf.parseUri(uri2);
16
+ t.ok(uri.family === 'ipv4', ' Srf.parseUri can parse sip URI with param and headers');
17
+ t.ok(uri.scheme === 'sip', ' Srf.parseUri can parse sip URI with param and headers');
18
+ t.ok(uri.user === '+12345612341t2', ' Srf.parseUri can parse sip URI with param and headers');
19
+ t.ok(uri.password === undefined, ' Srf.parseUri can parse sip URI with param and headers');
20
+ t.ok(uri.host === 'sip.jambonz.xyz', ' Srf.parseUri can parse sip URI with param and headers');
21
+ // t.ok(uri.port === undefined, ' Srf.parseUri can parse sip URI with param and headers');
22
+ t.ok(uri.params.param1 === 'value1', ' Srf.parseUri can parse sip URI with param and headers');
23
+ t.ok(uri.headers['User-To-User'] === 'XX12344321;encoding=ascii', ' Srf.parseUri can parse sip URI with param and headers');
24
+ t.ok(uri.headers.baba === 'lala', ' Srf.parseUri can parse sip URI with param and headers');
25
+ t.ok(Srf.stringifyUri(uri) === uri2, ' Srf.parseUri can parse sip URI with param and headers');
12
26
  let telUri = Srf.parseUri('<tel:+1-201-555-0123;phone-context=drachtio.org;ext=1>');
13
27
  t.ok(telUri.scheme === 'tel', 'Srf.parseUri can parse tel uri');
14
28
  t.ok(telUri.number === '+1-201-555-0123', 'Srf.parseUri can parse tel uri');