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

url.parse outputs incorrect url object #5755

Closed
pawanrawal opened this issue Mar 17, 2016 · 3 comments
Closed

url.parse outputs incorrect url object #5755

pawanrawal opened this issue Mar 17, 2016 · 3 comments
Labels
invalid Issues and PRs that are invalid.

Comments

@pawanrawal
Copy link

  • Version: 4.3.0
  • Platform: Darwin Apples-MacBook-Pro-2.local 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64

When I try to parse a url which has a port but no protocol, node returns protocol as the host name as part of the url object.

url.parse('localhost:8080/api/user') returns

{
  protocol: 'localhost:',
  slashes: null,
  auth: null,
  host: '8080',
  port: null,
  hostname: '8080',
  hash: null,
  search: null,
  query: null,
  pathname: '/api/user',
  path: '/api/user',
  href: 'localhost:8080/api/user'
}

Host, protocol and port all here messed up here.

@pawanrawal pawanrawal changed the title url.parse outputs incorrect protocol url.parse outputs incorrect url object Mar 17, 2016
@ChALkeR
Copy link
Member

ChALkeR commented Mar 17, 2016

No, it's completely valid.

@ChALkeR ChALkeR added the invalid Issues and PRs that are invalid. label Mar 17, 2016
@ChALkeR
Copy link
Member

ChALkeR commented Mar 17, 2016

Url does not not necessary have http or https protocol.

In A:B/C/D, A: is the protocol, B is the host, /C/D/ is the path.

@ChALkeR ChALkeR closed this as completed Mar 17, 2016
@williamkapke
Copy link
Contributor

@pawanrawal, I think a better way to explain might be:

According to RFC 2396, section 3.2. Authority Component:

The authority component is preceded by a double slash "//" and is terminated by the next slash "/", question-mark "?", or by the end of the URI.

...meaning it requires // to start the authority part- so in your example, it is considered the scheme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Issues and PRs that are invalid.
Projects
None yet
Development

No branches or pull requests

3 participants