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

Return value of url.parse() in nodejs version 16 and 17 is different from old version. #42231

Closed
LvChengbin opened this issue Mar 6, 2022 · 2 comments

Comments

@LvChengbin
Copy link

LvChengbin commented Mar 6, 2022

Version

16.14.0

Platform

No response

Subsystem

No response

What steps will reproduce the bug?

Run the following code with nodejs v15 and v16 gets different output.

const { parse } = require( 'url' );
parse( '//foo@bar' );

Output with nodejs 14:

{
    protocol: null,
    slashes: null,
    auth: null,
    host: null,
    port: null,
    hostname: null,
    hash: null,
    search: null,
    query: null,
    pathname: "//foo@bar",
    path: "//foo@bar",
    href: "//foo@bar"
}

Output with nodejs 16:

{
    protocol: null,
    slashes: true,
    auth: "foo",
    host: "bar",
    port: null,
    hostname: "bar",
    hash: null,
    search: null,
    query: null,
    pathname: null,
    path: null,
    href: "//foo@bar"
}

https://runkit.com/62249077dc641400085658be/6224907756c9c7000882de7a

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

I am not sure if it's a bug or not, but it's changed and cannot be found from documentation.
https://nodejs.org/dist/latest-v16.x/docs/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost

Additional information

No response

@Trott
Copy link
Member

Trott commented Mar 6, 2022

This was a bug fix in #41031.

In 14.x, adding a hash to the path changed the behavior which seemed surprising to put it mildly.

> url.parse('//foo@bar/what')
Url {
  protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: null,
  query: null,
  pathname: '//foo@bar/what',
  path: '//foo@bar/what',
  href: '//foo@bar/what'
}
> url.parse('//foo@bar/what#hey')
Url {
  protocol: null,
  slashes: true,
  auth: 'foo',
  host: 'bar',
  port: null,
  hostname: 'bar',
  hash: '#hey',
  search: null,
  query: null,
  pathname: '/what',
  path: '/what',
  href: '//foo@bar/what#hey'
}
>

In 16.x, the behavior is consistent with or without the hash.

@Trott
Copy link
Member

Trott commented Mar 6, 2022

I'm going to close this, but feel free to re-open or comment if there's more to discuss.

@Trott Trott closed this as completed Mar 6, 2022
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