Skip to content

Commit

Permalink
fix: ensure node support since node 10 (#119)
Browse files Browse the repository at this point in the history
* ensure node support since node 10

* run node 10 test separate

* fix

* use tape directly

* patch

* fix
  • Loading branch information
Uzlopak authored Jan 6, 2025
1 parent 4f6922a commit 1d4278a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 1d4278a

Please sign in to comment.