Skip to content

URL with omitted protocol is not parsed properly. #5

Open

Description

@akayami-legacy

Hi,

I've been working with the url extension and noticed it does not parse properly URL that do not contain protocol:

var url = require('url');
console.log(url.parse('//test.com/path?query=value'));

Is this a bug ?

Activity

  1. defunctzombie commented on Jun 6, 2014

    @defunctzombie
    Owner

    This is mostly a copy of the node.js url code. Do they have an open issue about this?

    https://github.com/joyent/node

  2. theetrain commented on Apr 10, 2017

    @theetrain

    I ran into this issue myself, and the solution was right under my nose. Change your code to:

    var url = require('url');
    console.log(url.parse('//test.com/path?query=value', false, true));

    This will parse the host and hostname correctly, but bear in mind the returned object.protocol will be null. More details in the node docs: https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost

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