镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

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.

Activity

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

    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