From 842805238cd86af3ef9a4fc3833695e8a21e2cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sat, 13 Apr 2024 11:34:35 +0200 Subject: [PATCH 1/3] Update for v5 (#80) * update * up --- .github/workflows/ci.yml | 2 +- .github/workflows/package-manager-ci.yml | 2 +- .taprc | 3 +++ package.json | 18 +++++++++--------- 4 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 .taprc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index babd56d..444baa7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,6 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0 with: license-check: true diff --git a/.github/workflows/package-manager-ci.yml b/.github/workflows/package-manager-ci.yml index 89d450f..113aad3 100644 --- a/.github/workflows/package-manager-ci.yml +++ b/.github/workflows/package-manager-ci.yml @@ -17,4 +17,4 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci-package-manager.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci-package-manager.yml@v4.1.0 diff --git a/.taprc b/.taprc new file mode 100644 index 0000000..343ddd5 --- /dev/null +++ b/.taprc @@ -0,0 +1,3 @@ +disable-coverage: true +files: + - test/**/*.test.js diff --git a/package.json b/package.json index 7aa187d..4a0568c 100644 --- a/package.json +++ b/package.json @@ -17,24 +17,24 @@ "homepage": "https://github.com/fastify/fast-uri", "scripts": { "bench": "node benchmark.js", + "lint": "standard | snazzy", "lint:fix": "standard --fix", - "test:lint": "standard | snazzy", - "test:typescript": "tsd", - "test:unit": "tap -J test/*.test.js", - "test:unit:dev": "tap -J test/*.test.js --coverage-report=html", - "test": "npm run test:lint && npm run test:unit && npm run test:typescript", - "test:ci": "npm run test:lint && npm run test:unit -- --cov --coverage-report=lcovonly && npm run test:typescript" + "test": "npm run lint && npm run test:unit && npm run test:typescript", + "test:ci": "npm run lint && npm run test:unit -- --coverage-report=lcovonly && npm run test:typescript", + "test:unit": "tap", + "test:unit:dev": "npm run test:unit -- --coverage-report=html", + "test:typescript": "tsd" }, "devDependencies": { + "@fastify/pre-commit": "^2.1.0", "benchmark": "^2.1.4", "coveralls": "^3.1.1", "snazzy": "^9.0.0", - "standard": "^17.0.0", - "tap": "^16.0.0", + "standard": "^17.1.0", + "tap": "^18.7.2", "tsd": "^0.31.0", "uri-js": "^4.4.1" }, - "dependencies": {}, "tap": { "check-coverage": false } From 88cb8714f18c93c0203dbc253ba994cbc84fc5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Thu, 25 Apr 2024 11:29:01 +0200 Subject: [PATCH 2/3] workflows: update and pin node LTS versions (#81) * update workflow * start from 16 --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 444baa7..e07183a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.2.0 with: license-check: true + node-versions: '["16", "18", "20"]' From 787a90427d8e9013935b9f6c529a579d80afa604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20Gro=C3=9F?= Date: Fri, 7 Jun 2024 23:48:32 +0200 Subject: [PATCH 3/3] perf: make ipv4 regex faster (#73) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: make ipv4 regex faster All credits for this regex to https://stackoverflow.com/a/36760050. The regex is both more correct and faster (https://esbench.com/bench/6532596e7ff73700a4debb6a). Examples: previous regex recognized "01.01.01.01" or "1.1.000.1" as correct ipv4 regex, but those aren't valid as per https://datatracker.ietf.org/doc/html/rfc5954#section-4.1. * avoid capture groups * update to fastest regexp variant * comment out 10.10.000.1110 * lint --------- Signed-off-by: Jacob Groß Co-authored-by: Gürgün Dayıoğlu --- lib/utils.js | 2 +- test/compatibility.test.js | 2 +- test/parse.test.js | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 78134c6..f7524ce 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -4,7 +4,7 @@ const { HEX } = require('./scopedChars') function normalizeIPv4 (host) { if (findToken(host, '.') < 3) { return { host, isIPV4: false } } - 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) || [] + const matches = host.match(/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/u) || [] const [address] = matches if (address) { return { host: stripLeadingZeros(address, '.'), isIPV4: true } diff --git a/test/compatibility.test.js b/test/compatibility.test.js index 73bc65a..0a57b89 100644 --- a/test/compatibility.test.js +++ b/test/compatibility.test.js @@ -10,7 +10,7 @@ test('compatibility Parse', (t) => { '//www.g.com/error\n/bleh/bleh', 'https://fastify.org', '//10.10.10.10', - '//10.10.000.10', + // '//10.10.000.10', <-- not a valid URI per URI spec: https://datatracker.ietf.org/doc/html/rfc5954#section-4.1 '//[2001:db8::7%en0]', '//[2001:dbZ::1]:80', '//[2001:db8::1]:80', diff --git a/test/parse.test.js b/test/parse.test.js index 2fe2133..fe7c44e 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -174,12 +174,21 @@ test('URI parse', (t) => { t.equal(components.query, undefined, 'query') t.equal(components.fragment, undefined, 'fragment') - // IPv4address with unformated 0 - components = URI.parse('//10.10.000.10') + // IPv4address with unformated 0 stay as-is + components = URI.parse('//10.10.000.10') // not valid as per https://datatracker.ietf.org/doc/html/rfc5954#section-4.1 t.equal(components.error, undefined, 'IPv4address errors') t.equal(components.scheme, undefined, 'scheme') t.equal(components.userinfo, undefined, 'userinfo') - t.equal(components.host, '10.10.0.10', 'host') + t.equal(components.host, '10.10.000.10', 'host') + t.equal(components.port, undefined, 'port') + t.equal(components.path, '', 'path') + t.equal(components.query, undefined, 'query') + t.equal(components.fragment, undefined, 'fragment') + components = URI.parse('//01.01.01.01') // not valid in URIs: https://datatracker.ietf.org/doc/html/rfc3986#section-7.4 + t.equal(components.error, undefined, 'IPv4address errors') + t.equal(components.scheme, undefined, 'scheme') + t.equal(components.userinfo, undefined, 'userinfo') + t.equal(components.host, '01.01.01.01', 'host') t.equal(components.port, undefined, 'port') t.equal(components.path, '', 'path') t.equal(components.query, undefined, 'query')