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

No support for "tel:xxxx", "mailto:xxx" like urls #177

Closed
daKmoR opened this issue Oct 28, 2022 · 0 comments · Fixed by #178
Closed

No support for "tel:xxxx", "mailto:xxx" like urls #177

daKmoR opened this issue Oct 28, 2022 · 0 comments · Fixed by #178

Comments

@daKmoR
Copy link

daKmoR commented Oct 28, 2022

I run all < href="x"> url through normalize... but it does fail on standard protocols like mailto:, tel: .

should that be supported or do I need to "filter" non-http-like URLs before?

Code to reproduce

import normalizeUrl from 'normalize-url';

// 1.
console.log(normalizeUrl('tel:004346382763'));

// 2.
console.log(normalizeUrl('mailto:office@foo.com'));

Expected behavior

Do not touch the URLs e.g. return tel:004346382763 and mailto:office@foo.com

Actual behavior

  1. it throws
TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:387:5)
    at URL.onParseError (node:internal/url:564:9)
    at new URL (node:internal/url:644:5)
    at normalizeUrl (file:///Users/html/rocket/node_modules/normalize-url/index.js:97:20)
    at file:///Users/html/rocket/packages/check-html-links/foo.js:3:13
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12) {
  input: 'http:tel:004346382763',
  code: 'ERR_INVALID_URL'
}
  1. Results in http://foo.com

Investigation

it always seems to prepend http: which leads to the invalid http:tel:004346382763 URL which then throws on the new URL here https://github.com/sindresorhus/normalize-url/blob/main/index.js#L96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant