Skip to content

net/url: better handling or documentation of IPv6 addresses in url.URL.Host #61276

@jjlin

Description

@jjlin

What did you do?

https://go.dev/play/p/Lypv_o9VMRf

host := "fc00::121:0:2:27"
url := url.URL{
	Scheme: "https",
	Host:   host,
	Path:   "/some/path",
}
fmt.Println(url.String())

What did you expect to see?

https://[fc00::121:0:2:27]/some/path

What did you see instead?

https://fc00::121:0:2:27/some/path

This ends up being interpreted as https://[fc00::121:0:2]:27/some/path.

The documentation for url.URL.Host is host or host:port, which leaves it unclear as to how a literal IPv6 address would be treated.

I think it makes more sense to treat a literal IPv6 address as just that, and require the user to specify [<ipv6-address>]:<port> if that's what they actually wanted, though I appreciate that there would be backward compatibility issues with that.

So at this point, it's probably best to just clarify the docs and add a reference to net.JoinHostPort. This could perhaps be done via #61093.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions