Skip to content

Parsing host without protocol #40

Open

Description

@ccorcos

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' }

Activity

  1. sc0Vu commented on Mar 9, 2018

    @sc0Vu

    I met this too.

  2. vv13 commented on Sep 6, 2018

    @vv13

    i judge protocol exists before parse:

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

    hope it can help you .

  3. ljharb commented on Jan 27, 2021

    @ljharb
    Collaborator

    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)

  4. ameshkin commented on Jan 25, 2023

    @ameshkin

    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.

  5. ameshkin commented on Jan 25, 2023

    @ameshkin

    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.

  6. ljharb commented on Jan 25, 2023

    @ljharb
    Collaborator

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions