From 1d4278a949e09e3ca23f8f16945d109cdec3f26a Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Mon, 6 Jan 2025 11:07:46 +0100 Subject: [PATCH] fix: ensure node support since node 10 (#119) * ensure node support since node 10 * run node 10 test separate * fix * use tape directly * patch * fix --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++++++ index.js | 10 +++++----- package.json | 2 +- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2c109e..588eca0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,41 @@ on: - '*.md' jobs: + test-regression-check-node10: + name: Test compatibility with Node.js 10 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - uses: actions/setup-node@v4 + with: + node-version: '10' + cache: 'npm' + cache-dependency-path: package.json + check-latest: true + + - name: Install + run: | + npm install --ignore-scripts + + - name: Copy project as fast-uri to node_node_modules + run: | + rm -rf ./node_modules/fast-uri/lib && + rm -rf ./node_modules/fast-uri/index.js && + cp -r ./lib ./node_modules/fast-uri/lib && + cp ./index.js ./node_modules/fast-uri/index.js + + - name: Run tests + run: | + npm run test:unit + env: + NODE_OPTIONS: no-network-family-autoselection + test: + needs: + - test-regression-check-node10 uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5 with: license-check: true diff --git a/index.js b/index.js index 19b114d..86a09e5 100644 --- a/index.js +++ b/index.js @@ -120,7 +120,7 @@ function serialize (cmpts, opts) { const schemeHandler = SCHEMES[(options.scheme || components.scheme || '').toLowerCase()] // perform scheme specific serialization - if (schemeHandler?.serialize) schemeHandler.serialize(components, options) + if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options) if (components.path !== undefined) { if (!options.skipEscape) { @@ -252,7 +252,7 @@ function parse (uri, opts) { // check if scheme can't handle IRIs if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) { // if host component is a domain name - if (parsed.host && (options.domainHost || schemeHandler?.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) { + if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && isIP === false && nonSimpleDomain(parsed.host)) { // convert Unicode IDN -> ASCII IDN try { parsed.host = URL.domainToASCII(parsed.host.toLowerCase()) @@ -270,16 +270,16 @@ function parse (uri, opts) { if (gotEncoding && parsed.host !== undefined) { parsed.host = unescape(parsed.host) } - if (parsed.path?.length) { + if (parsed.path && parsed.path.length) { parsed.path = escape(unescape(parsed.path)) } - if (parsed.fragment?.length) { + if (parsed.fragment && parsed.fragment.length) { parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment)) } } // perform scheme specific parsing - if (schemeHandler?.parse) { + if (schemeHandler && schemeHandler.parse) { schemeHandler.parse(parsed, options) } } else { diff --git a/package.json b/package.json index 607307d..75b0497 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "lint": "eslint", "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", - "test:unit": "npx tape test/**/*.js", + "test:unit": "tape test/**/*.js", "test:unit:dev": "npm run test:unit -- --coverage-report=html", "test:typescript": "tsd" },