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

Parsing host without protocol #40

Open
ccorcos opened this issue Nov 9, 2017 · 6 comments
Open

Parsing host without protocol #40

ccorcos opened this issue Nov 9, 2017 · 6 comments

Comments

@ccorcos
Copy link

ccorcos commented Nov 9, 2017

This library doesnt seem to parse the host properly when there isnt a protocol.

> u.parse("www.google.com/yay?q=10&q=12")
Url {
  protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: '?q=10&q=12',
  query: 'q=10&q=12',
  pathname: 'www.google.com/yay',
  path: 'www.google.com/yay?q=10&q=12',
  href: 'www.google.com/yay?q=10&q=12' }
@sc0Vu
Copy link

sc0Vu commented Mar 9, 2018

I met this too.

@vv13
Copy link

vv13 commented Sep 6, 2018

i judge protocol exists before parse:

  if (/http/gi.test(url)) {
    url.parse(url)
  }

hope it can help you .

@ljharb
Copy link
Collaborator

ljharb commented Jan 27, 2021

What does node's core url module do here?

(specifically, without a protocol, it's not actually a URL, so this might simply be user error)

@ameshkin
Copy link

I have seen many cases of protocol less links such as //google.com which are annoying. Everyone should always just use SSL and https.

This library does not correctly handle these links well but you can use regex to look for //. I may fork and update this package.

@ameshkin
Copy link

ameshkin commented Jan 25, 2023

This library doesnt seem to parse the host properly when there isnt a protocol.

> u.parse("www.google.com/yay?q=10&q=12")
Url {
  protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: '?q=10&q=12',
  query: 'q=10&q=12',
  pathname: 'www.google.com/yay',
  path: 'www.google.com/yay?q=10&q=12',
  href: 'www.google.com/yay?q=10&q=12' }

Without // , http or https, it's not a domain.

www.google.com/yay?q=10&q=12 needs to have // instead of www.

@ljharb
Copy link
Collaborator

ljharb commented Jan 25, 2023

@ameshkin this library matches what node’s core url module does, so if that one doesn’t do it, this one shouldn’t either.

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

5 participants