fast-uri 2.2.0 → 2.3.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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Set default behavior to automatically convert line endings
2
+ * text=auto eol=lf
@@ -2,6 +2,11 @@ name: CI
2
2
 
3
3
  on:
4
4
  push:
5
+ branches:
6
+ - main
7
+ - master
8
+ - next
9
+ - 'v*'
5
10
  paths-ignore:
6
11
  - 'docs/**'
7
12
  - '*.md'
@@ -3,64 +3,18 @@ name: package-manager-ci
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
7
-
8
- permissions:
9
- contents: read
6
+ - main
7
+ - master
8
+ - next
9
+ - 'v*'
10
+ paths-ignore:
11
+ - 'docs/**'
12
+ - '*.md'
13
+ pull_request:
14
+ paths-ignore:
15
+ - 'docs/**'
16
+ - '*.md'
10
17
 
11
18
  jobs:
12
- pnpm:
13
- runs-on: ${{ matrix.os }}
14
-
15
- strategy:
16
- matrix:
17
- # Maintenance and active LTS
18
- node-version: [14, 16]
19
- os: [ubuntu-18.04]
20
-
21
- steps:
22
- - uses: actions/checkout@v3
23
- with:
24
- persist-credentials: false
25
-
26
- - name: Use Node.js
27
- uses: actions/setup-node@v3
28
- with:
29
- node-version: ${{ matrix.node-version }}
30
-
31
- - name: Install with pnpm
32
- run: |
33
- curl -L https://unpkg.com/@pnpm/self-installer | node
34
- pnpm install
35
-
36
- - name: Run tests
37
- run: |
38
- pnpm run test
39
-
40
- yarn:
41
- runs-on: ${{ matrix.os }}
42
-
43
- strategy:
44
- matrix:
45
- # Maintenance and active LTS
46
- node-version: [14, 16]
47
- os: [ubuntu-18.04]
48
-
49
- steps:
50
- - uses: actions/checkout@v3
51
- with:
52
- persist-credentials: false
53
-
54
- - name: Use Node.js
55
- uses: actions/setup-node@v3
56
- with:
57
- node-version: ${{ matrix.node-version }}
58
-
59
- - name: Install with yarn
60
- run: |
61
- curl -o- -L https://yarnpkg.com/install.sh | bash
62
- yarn install --ignore-engines
63
-
64
- - name: Run tests
65
- run: |
66
- yarn run test
19
+ test:
20
+ uses: fastify/workflows/.github/workflows/plugins-ci-package-manager.yml@v3
package/.taprc ADDED
@@ -0,0 +1 @@
1
+ check-coverage: false
package/benchmark.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const benchmark = require('benchmark')
2
4
  const suite = new benchmark.Suite()
3
5
  const fasturi = require('./')
package/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const URL = require('url')
4
3
  const { normalizeIPv6, normalizeIPv4, removeDotSegments, recomposeAuthority, normalizeComponentEncoding } = require('./lib/utils')
5
4
  const SCHEMES = require('./lib/schemes')
6
5
 
@@ -160,7 +159,7 @@ function serialize (cmpts, opts) {
160
159
  }
161
160
 
162
161
  if (authority === undefined) {
163
- s = s.replace(/^\/\//, '/%2F') // don't allow the path to start with "//"
162
+ s = s.replace(/^\/\//u, '/%2F') // don't allow the path to start with "//"
164
163
  }
165
164
 
166
165
  uriTokens.push(s)
@@ -178,7 +177,20 @@ function serialize (cmpts, opts) {
178
177
  return uriTokens.join('')
179
178
  }
180
179
 
181
- const URI_PARSE = /^(?:([^:/?#]+):)?(?:\/\/((?:([^/?#@]*)@)?(\[[^/?#\]]+\]|[^/?#:]*)(?::(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i
180
+ const hexLookUp = Array.from({ length: 127 }, (v, k) => /[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(k)))
181
+
182
+ function nonSimpleDomain (value) {
183
+ let code = 0
184
+ for (let i = 0, len = value.length; i < len; ++i) {
185
+ code = value.charCodeAt(i)
186
+ if (code > 126 || hexLookUp[code]) {
187
+ return true
188
+ }
189
+ }
190
+ return false
191
+ }
192
+
193
+ const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u
182
194
 
183
195
  function parse (uri, opts) {
184
196
  const options = Object.assign({}, opts)
@@ -239,7 +251,7 @@ function parse (uri, opts) {
239
251
  // check if scheme can't handle IRIs
240
252
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
241
253
  // if host component is a domain name
242
- if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost))) {
254
+ if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && nonSimpleDomain(parsed.host)) {
243
255
  // convert Unicode IDN -> ASCII IDN
244
256
  try {
245
257
  parsed.host = URL.domainToASCII(parsed.host.toLowerCase())
package/lib/schemes.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const UUID_REG = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/
4
- const URN_REG = /([A-Za-z0-9][A-Za-z0-9-]{0,31}):(([A-Za-z0-9()+,\-.:=@;$_!*']|%[0-9A-Fa-f]{2})+)/
3
+ const UUID_REG = /^[\da-f]{8}\b-[\da-f]{4}\b-[\da-f]{4}\b-[\da-f]{4}\b-[\da-f]{12}$/iu
4
+ const URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu
5
5
 
6
6
  function isSecure (wsComponents) {
7
7
  return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === 'wss'
package/lib/utils.js CHANGED
@@ -4,7 +4,7 @@ const { HEX } = require('./scopedChars')
4
4
 
5
5
  function normalizeIPv4 (host) {
6
6
  if (findToken(host, '.') < 3) { return { host, isIPV4: false } }
7
- const matches = host.match(/^(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/) || []
7
+ const matches = host.match(/^(\b[01]?\d{1,2}|\b2[0-4]\d|\b25[0-5])(\.([01]?\d{1,2}|2[0-4]\d|25[0-5])){3}$/u) || []
8
8
  const [address] = matches
9
9
  if (address) {
10
10
  return { host: stripLeadingZeros(address, '.'), isIPV4: true }
@@ -138,10 +138,10 @@ function findToken (str, token) {
138
138
  return ind
139
139
  }
140
140
 
141
- const RDS1 = /^\.\.?\//
142
- const RDS2 = /^\/\.(\/|$)/
143
- const RDS3 = /^\/\.\.(\/|$)/
144
- const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/
141
+ const RDS1 = /^\.\.?\//u
142
+ const RDS2 = /^\/\.(?:\/|$)/u
143
+ const RDS3 = /^\/\.\.(?:\/|$)/u
144
+ const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/u
145
145
 
146
146
  function removeDotSegments (input) {
147
147
  const output = []
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fast-uri",
3
3
  "description": "Dependency free RFC 3986 URI toolbox",
4
- "version": "2.2.0",
4
+ "version": "2.3.1",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
7
7
  "types": "types/index.d.ts",
@@ -9,12 +9,12 @@
9
9
  "author": "Vincent Le Goff <vince.legoff@gmail.com> (https://github.com/zekth)",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/fastify/fast-uri"
12
+ "url": "git+https://github.com/fastify/fast-uri.git"
13
13
  },
14
14
  "bugs": {
15
15
  "url": "https://github.com/fastify/fast-uri/issues"
16
16
  },
17
- "homepage":"https://github.com/fastify/fast-uri",
17
+ "homepage": "https://github.com/fastify/fast-uri",
18
18
  "scripts": {
19
19
  "bench": "node benchmark.js",
20
20
  "lint:fix": "standard --fix",
@@ -31,11 +31,7 @@
31
31
  "snazzy": "^9.0.0",
32
32
  "standard": "^17.0.0",
33
33
  "tap": "^16.0.0",
34
- "tsd": "^0.24.1",
34
+ "tsd": "^0.31.0",
35
35
  "uri-js": "^4.4.1"
36
- },
37
- "dependencies": {},
38
- "tap": {
39
- "check-coverage": false
40
36
  }
41
37
  }