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

Hostname detection fails for URLs starting with https:/// #365

Open
konstantinblaesi opened this issue Jan 6, 2018 · 1 comment
Open

Comments

@konstantinblaesi
Copy link
Contributor

konstantinblaesi commented Jan 6, 2018

const URI = require('urijs');

URI.preventInvalidHostname = false;
const url = URI('https:///cdn.shopify.com/s/files/1/0333/9621/files/forbiiden_banner_small.jpg?2662936180569856865');

url._parts looks like this:

{
  potocol: 'https',
  username: null,
  password: null,
  hostname: null,
  urn: null,
  port: null,
  path: '/cdn.shopify.com/s/files/1/0333/9621/files/forbiiden_banner_small.jpg',
  query: '2662936180569856865',
  fragment: null,
  preventInvalidHostname: false,
  duplicateQueryParameters: false,
  escapeQuerySpace: true
}

When setting URI.preventInvalidHostname = true;

Uncaught TypeError: Hostname cannot be empty, if protocol is https

is thrown. This was initially reported for simplecrawler/simplecrawler#415. Chrome handles the URL without issues. Do you think URI.js should be more liberal and fix the URL before parsing it?

@rodneyrehm
Copy link
Member

URL, Firefox, Chrome and curl agree, they rewrite https:/// to https://. URL, Chrome and Firefox even rewrite https:////, but curl reports curl: (3) Bad URL.

The question is for which schemes/protocols this should apply, an obvious exception is file://.

Do you want to give this a try?

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

No branches or pull requests

2 participants