fast-uri 3.0.6 → 3.1.1

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/test/util.test.js CHANGED
@@ -2,22 +2,37 @@
2
2
 
3
3
  const test = require('tape')
4
4
  const {
5
- stringArrayToHexStripped
5
+ stringArrayToHexStripped,
6
+ removeDotSegments
6
7
  } = require('../lib/utils')
7
8
 
8
9
  test('stringArrayToHexStripped', (t) => {
9
10
  const testCases = [
10
- [[['0', '0', '0', '0']], ''],
11
- [[['0', '0', '0', '0'], false], ''],
12
- [[['0', '0', '0', '0'], true], '0'],
13
- [[['0', '1', '0', '0'], false], '100'],
14
- [[['1', '0', '0', '0'], false], '1000'],
15
- [[['1', '0', '0', '0'], true], '1000']
11
+ [['0', '0', '0', '0'], ''],
12
+ [['0', '0', '0', '1'], '1'],
13
+ [['0', '0', '1', '0'], '10'],
14
+ [['0', '1', '0', '0'], '100'],
15
+ [['1', '0', '0', '0'], '1000'],
16
+ [['1', '0', '0', '1'], '1001'],
16
17
  ]
17
18
 
18
19
  t.plan(testCases.length)
19
20
 
20
21
  testCases.forEach(([input, expected]) => {
21
- t.same(stringArrayToHexStripped(input[0], input[1]), expected)
22
+ t.same(stringArrayToHexStripped(input), expected)
23
+ })
24
+ })
25
+
26
+ // Just fixtures, because this function already tested by resolve
27
+ test('removeDotSegments', (t) => {
28
+ const testCases = []
29
+ // https://github.com/fastify/fast-uri/issues/139
30
+ testCases.push(['WS:/WS://1305G130505:1&%0D:1&C(XXXXX*)))))))XXX130505:UUVUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$aaaaaaaaaaaa13a',
31
+ 'WS:/WS://1305G130505:1&%0D:1&C(XXXXX*)))))))XXX130505:UUVUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$aaaaaaaaaaaa13a'])
32
+
33
+ t.plan(testCases.length)
34
+
35
+ testCases.forEach(([input, expected]) => {
36
+ t.same(removeDotSegments(input), expected)
22
37
  })
23
38
  })
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "strict": true,
6
+ "noImplicitAny": true,
7
+ "target": "es2015"
8
+ }
9
+ }
package/types/index.d.ts CHANGED
@@ -10,6 +10,11 @@ declare namespace fastUri {
10
10
  query?: string;
11
11
  fragment?: string;
12
12
  reference?: string;
13
+ nid?: string;
14
+ nss?: string;
15
+ resourceName?: string;
16
+ secure?: boolean;
17
+ uuid?: string;
13
18
  error?: string;
14
19
  }
15
20
  export interface Options {
@@ -19,6 +24,8 @@ declare namespace fastUri {
19
24
  domainHost?: boolean;
20
25
  absolutePath?: boolean;
21
26
  tolerant?: boolean;
27
+ skipEscape?: boolean;
28
+ nid?: string;
22
29
  }
23
30
 
24
31
  /**
@@ -1,21 +0,0 @@
1
- # Number of days of inactivity before an issue becomes stale
2
- daysUntilStale: 15
3
- # Number of days of inactivity before a stale issue is closed
4
- daysUntilClose: 7
5
- # Issues with these labels will never be considered stale
6
- exemptLabels:
7
- - "discussion"
8
- - "feature request"
9
- - "bug"
10
- - "help wanted"
11
- - "plugin suggestion"
12
- - "good first issue"
13
- # Label to use when marking an issue as stale
14
- staleLabel: stale
15
- # Comment to post when marking an issue as stale. Set to `false` to disable
16
- markComment: >
17
- This issue has been automatically marked as stale because it has not had
18
- recent activity. It will be closed if no further activity occurs. Thank you
19
- for your contributions.
20
- # Comment to post when closing a stale issue. Set to `false` to disable
21
- closeComment: false
@@ -1,8 +0,0 @@
1
- comment: |
2
- Hello! Thank you for contributing!
3
- It appears that you have changed the code, but the tests that verify your change are missing. Could you please add them?
4
- fileExtensions:
5
- - '.ts'
6
- - '.js'
7
-
8
- testDir: 'test'
package/benchmark.js DELETED
@@ -1,105 +0,0 @@
1
- 'use strict'
2
-
3
- const benchmark = require('benchmark')
4
- const suite = new benchmark.Suite()
5
- const fasturi = require('./')
6
- const urijs = require('uri-js')
7
-
8
- const base = 'uri://a/b/c/d;p?q'
9
-
10
- const domain = 'https://example.com/foo#bar$fiz'
11
- const ipv4 = '//10.10.10.10'
12
- const ipv6 = '//[2001:db8::7]'
13
- const urn = 'urn:foo:a123,456'
14
- const urnuuid = 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
15
-
16
- // Initialization as there is a lot to parse at first
17
- // eg: regexes
18
- fasturi.parse(domain)
19
- urijs.parse(domain)
20
-
21
- suite.add('fast-uri: parse domain', function () {
22
- fasturi.parse(domain)
23
- })
24
- suite.add('urijs: parse domain', function () {
25
- urijs.parse(domain)
26
- })
27
- suite.add('WHATWG URL: parse domain', function () {
28
- // eslint-disable-next-line
29
- new URL(domain)
30
- })
31
- suite.add('fast-uri: parse IPv4', function () {
32
- fasturi.parse(ipv4)
33
- })
34
- suite.add('urijs: parse IPv4', function () {
35
- urijs.parse(ipv4)
36
- })
37
- suite.add('fast-uri: parse IPv6', function () {
38
- fasturi.parse(ipv6)
39
- })
40
- suite.add('urijs: parse IPv6', function () {
41
- urijs.parse(ipv6)
42
- })
43
- suite.add('fast-uri: parse URN', function () {
44
- fasturi.parse(urn)
45
- })
46
- suite.add('urijs: parse URN', function () {
47
- urijs.parse(urn)
48
- })
49
- suite.add('WHATWG URL: parse URN', function () {
50
- // eslint-disable-next-line
51
- new URL(urn)
52
- })
53
- suite.add('fast-uri: parse URN uuid', function () {
54
- fasturi.parse(urnuuid)
55
- })
56
- suite.add('urijs: parse URN uuid', function () {
57
- urijs.parse(urnuuid)
58
- })
59
- suite.add('fast-uri: serialize uri', function () {
60
- fasturi.serialize({
61
- scheme: 'uri',
62
- userinfo: 'foo:bar',
63
- host: 'example.com',
64
- port: 1,
65
- path: 'path',
66
- query: 'query',
67
- fragment: 'fragment'
68
- })
69
- })
70
- suite.add('urijs: serialize uri', function () {
71
- urijs.serialize({
72
- scheme: 'uri',
73
- userinfo: 'foo:bar',
74
- host: 'example.com',
75
- port: 1,
76
- path: 'path',
77
- query: 'query',
78
- fragment: 'fragment'
79
- })
80
- })
81
- suite.add('fast-uri: serialize IPv6', function () {
82
- fasturi.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
83
- })
84
- suite.add('urijs: serialize IPv6', function () {
85
- urijs.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
86
- })
87
- suite.add('fast-uri: serialize ws', function () {
88
- fasturi.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
89
- })
90
- suite.add('urijs: serialize ws', function () {
91
- urijs.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
92
- })
93
- suite.add('fast-uri: resolve', function () {
94
- fasturi.resolve(base, '../../../g')
95
- })
96
- suite.add('urijs: resolve', function () {
97
- urijs.resolve(base, '../../../g')
98
- })
99
- suite.on('cycle', cycle)
100
-
101
- suite.run()
102
-
103
- function cycle (e) {
104
- console.log(e.target.toString())
105
- }
@@ -1,30 +0,0 @@
1
- 'use strict'
2
-
3
- const HEX = {
4
- 0: 0,
5
- 1: 1,
6
- 2: 2,
7
- 3: 3,
8
- 4: 4,
9
- 5: 5,
10
- 6: 6,
11
- 7: 7,
12
- 8: 8,
13
- 9: 9,
14
- a: 10,
15
- A: 10,
16
- b: 11,
17
- B: 11,
18
- c: 12,
19
- C: 12,
20
- d: 13,
21
- D: 13,
22
- e: 14,
23
- E: 14,
24
- f: 15,
25
- F: 15
26
- }
27
-
28
- module.exports = {
29
- HEX
30
- }
package/test/.gitkeep DELETED
File without changes
@@ -1,131 +0,0 @@
1
- 'use strict'
2
-
3
- const test = require('tape')
4
- const fastifyURI = require('../')
5
- const urijs = require('uri-js')
6
-
7
- test('compatibility Parse', (t) => {
8
- const toParse = [
9
- '//www.g.com/error\n/bleh/bleh',
10
- 'https://fastify.org',
11
- '/definitions/Record%3Cstring%2CPerson%3E',
12
- '//10.10.10.10',
13
- // '//10.10.000.10', <-- not a valid URI per URI spec: https://datatracker.ietf.org/doc/html/rfc5954#section-4.1
14
- '//[2001:db8::7%en0]',
15
- '//[2001:dbZ::1]:80',
16
- '//[2001:db8::1]:80',
17
- '//[2001:db8::001]:80',
18
- 'uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body',
19
- 'http://user:pass@example.com:123/one/space in.url?q1=a1&q2=a2#body',
20
- 'http://User:Pass@example.com:123/one/space in.url?q1=a1&q2=a2#body',
21
- 'http://A%3AB@example.com:123/one/space',
22
- '//[::ffff:129.144.52.38]',
23
- 'uri://10.10.10.10.example.com/en/process',
24
- '//[2606:2800:220:1:248:1893:25c8:1946]/test',
25
- 'ws://example.com/chat',
26
- 'ws://example.com/foo?bar=baz',
27
- 'wss://example.com/?bar=baz',
28
- 'wss://example.com/chat',
29
- 'wss://example.com/foo?bar=baz',
30
- 'wss://example.com/?bar=baz',
31
- 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
32
- 'urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6',
33
- 'urn:example:%D0%B0123,z456',
34
- '//[2606:2800:220:1:248:1893:25c8:1946:43209]',
35
- 'http://foo.bar',
36
- 'http://',
37
- '#/$defs/stringMap',
38
- '#/$defs/string%20Map',
39
- '#/$defs/string Map',
40
- '//?json=%7B%22foo%22%3A%22bar%22%7D'
41
- // 'mailto:chris@example.com'-203845,
42
- // 'mailto:infobot@example.com?subject=current-issue',
43
- // 'mailto:infobot@example.com?body=send%20current-issue',
44
- // 'mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index',
45
- // 'mailto:list@example.org?In-Reply-To=%3C3469A91.D10AF4C@example.com%3E',
46
- // 'mailto:majordomo@example.com?body=subscribe%20bamboo-l',
47
- // 'mailto:joe@example.com?cc=bob@example.com&body=hello',
48
- // 'mailto:gorby%25kremvax@example.com',
49
- // 'mailto:unlikely%3Faddress@example.com?blat=foop',
50
- // 'mailto:Mike%26family@example.org',
51
- // 'mailto:%22not%40me%22@example.org',
52
- // 'mailto:%22oh%5C%5Cno%22@example.org',
53
- // 'mailto:%22%5C%5C%5C%22it\'s%5C%20ugly%5C%5C%5C%22%22@example.org',
54
- // 'mailto:user@example.org?subject=caf%C3%A9',
55
- // 'mailto:user@example.org?subject=%3D%3Futf-8%3FQ%3Fcaf%3DC3%3DA9%3F%3D',
56
- // 'mailto:user@example.org?subject=%3D%3Fiso-8859-1%3FQ%3Fcaf%3DE9%3F%3D',
57
- // 'mailto:user@example.org?subject=caf%C3%A9&body=caf%C3%A9',
58
- // 'mailto:user@%E7%B4%8D%E8%B1%86.example.org?subject=Test&body=NATTO'
59
- ]
60
- toParse.forEach((x) => {
61
- t.same(fastifyURI.parse(x), urijs.parse(x), 'Compatibility parse: ' + x)
62
- })
63
- t.end()
64
- })
65
-
66
- test('compatibility serialize', (t) => {
67
- const toSerialize = [
68
- { host: '10.10.10.10.example.com' },
69
- { host: '2001:db8::7' },
70
- { host: '::ffff:129.144.52.38' },
71
- { host: '2606:2800:220:1:248:1893:25c8:1946' },
72
- { host: '10.10.10.10.example.com' },
73
- { host: '10.10.10.10' },
74
- { path: '?query' },
75
- { path: 'foo:bar' },
76
- { path: '//path' },
77
- {
78
- scheme: 'uri',
79
- host: 'example.com',
80
- port: '9000'
81
- },
82
- {
83
- scheme: 'uri',
84
- userinfo: 'foo:bar',
85
- host: 'example.com',
86
- port: 1,
87
- path: 'path',
88
- query: 'query',
89
- fragment: 'fragment'
90
- },
91
- {
92
- scheme: '',
93
- userinfo: '',
94
- host: '',
95
- port: 0,
96
- path: '',
97
- query: '',
98
- fragment: ''
99
- },
100
- {
101
- scheme: undefined,
102
- userinfo: undefined,
103
- host: undefined,
104
- port: undefined,
105
- path: undefined,
106
- query: undefined,
107
- fragment: undefined
108
- },
109
- { host: 'fe80::a%en1' },
110
- { host: 'fe80::a%25en1' },
111
- {
112
- scheme: 'ws',
113
- host: 'example.com',
114
- resourceName: '/foo?bar',
115
- secure: true
116
- },
117
- {
118
- scheme: 'scheme',
119
- path: 'with:colon'
120
- }
121
- ]
122
- toSerialize.forEach((x) => {
123
- const r = JSON.stringify(x)
124
- t.same(
125
- fastifyURI.serialize(x),
126
- urijs.serialize(x),
127
- 'Compatibility serialize: ' + JSON.stringify(r)
128
- )
129
- })
130
- t.end()
131
- })