Skip to content

The deprecated url.format formats ipv6 localhost address wronglyΒ #36654

Closed
@chenxsan

Description

@chenxsan
  • Version: I've tested it against Node.js 11, 12, 13, 14, 15
  • Platform: I've tested it on macOS Big Sur.
  • Subsystem:

What steps will reproduce the bug?

Create a new format.js file with content below:

const url = require('url')
console.log(url.format({
    protocol: 'http',
    hostname: '[::]'
}))

Then run it with node format.js.

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

Always.

What is the expected behavior?

Should output http://[::] instead.

What do you see instead?

It will output http://[[::]] which I believe is wrong.

Additional information

  1. I know url.format(urlobject) was deprecated as per https://nodejs.org/api/url.html#url_url_format_urlobject, but there're still libraries using it.
  2. url.format(new URL('http://[::]')) would output http://[::]/ as I expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    urlIssues and PRs related to the legacy built-in url module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions