Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure node support since node 10 #119

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit but parsed.fragment would also cover the length check here if a string indeed exists

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gurgunday Fancy throwing a PR together?

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
Loading