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

net: JoinHostPort should not add [ ] when the host is ipv6 and it is surrounded by brackets #26006

Closed
Sherlock-Holo opened this issue Jun 22, 2018 · 14 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@Sherlock-Holo
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10.3 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sherlock/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/sherlock/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build032343756=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/faeZpo0P020

What did you expect to see?

[fe80::2b4f:2681:f032:55fd]:80

What did you see instead?

[[fe80::2b4f:2681:f032:55fd]]:80

I think JoinHostPort can identify this host is an ipv6 address, and we can use strings.HasPrefix and strings.HasSuffix to check if the ipv6 address already has the bracket. If it already has brackets, I think JoinHostPort should not add it again

@agnivade
Copy link
Contributor

The function works as documented -

If host contains a colon, as found in literal IPv6 addresses, then JoinHostPort returns "[host]:port".

Checking for [ and ] might be overdo when the user can do it themselves. And moreover, it is a breaking change, and might have unforeseen consequences.

/cc @bradfitz.

@agnivade agnivade changed the title net.JoinHostPort should not add [ ] when the host is ipv6 and it is surrounded by brackets net: JoinHostPort should not add [ ] when the host is ipv6 and it is surrounded by brackets Jun 22, 2018
@agnivade agnivade added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jun 22, 2018
@agnivade agnivade added this to the Unplanned milestone Jun 22, 2018
@ianlancetaylor
Copy link
Contributor

CC @mikioh

@Sherlock-Holo
Copy link
Author

@agnivade I wonder why it's a breaking change because no matter you give the ipv6 has [ ], it returns the right string like [fe08:xx:xx::x]:80

@Sherlock-Holo
Copy link
Author

@agnivade like you say the users can check by themselves, but if the net module in std can do it better, why users need to write an additional function to do this job

@bradfitz
Copy link
Contributor

I don't think it's legal to have a hostname with brackets. I think they're only valid in the host:port form.

@Sherlock-Holo
Copy link
Author

@bradfitz yeah but in golang, when we use Dial , if the address is ipaddress:port, the ipv6 address should be wrapped by the square brackets, if an address is wrapped by [ ] and it has more than one :, I think it must be an ipv6 address.

@agnivade
Copy link
Contributor

@Sherlock-Holo - It's a breaking change because you want it to return [fe80::2b4f:2681:f032:55fd]:80 whereas it returns [[fe80::2b4f:2681:f032:55fd]]:80 currently. So programs expecting [[..]] will break.

@Sherlock-Holo
Copy link
Author

@agnivade yes some programs check if [[..]] or not, but if JoinHostPort return [fe80::2b4f:2681:f032:55fd]:80 ,the check will not break because we get the right address, and programs work well without [[..]] error

@bradfitz
Copy link
Contributor

@agnivade, I'm not concerned about breaking people who depend on getting bogus [[...]]. I don't think such people exist, because that's already bogus. But I don't think we should make it easier for people to do bogus things.

I'm just not seeing how somebody ends up with brackets around an IPv6 literal without a port. Where do such values come from that you then need to call JoinHostPort with them?

@Sherlock-Holo
Copy link
Author

for example, som people write fe80::2b4f:2681:f032:55fd into a config file, some peolple write [fe80::2b4f:2681:f032:55fd]

@bradfitz
Copy link
Contributor

@Sherlock-Holo, what other software accepts an IP (without a port) with brackets?

@Sherlock-Holo
Copy link
Author

At most time, config file is written by human.

Some guys think writing an ipv6 wrapped with brackets is a good idea because if we open a website on chrome with ipv6 address instead of hostname, they should make the ipv6 wrapped with brackets.

Others think ipv6 just an ip address why ipv6 is different from ipv4, so they write ipv6 without brackets.

@rsc
Copy link
Contributor

rsc commented Jun 25, 2018

JoinHostPort joins a host and a port. [ipv6addr] is not a host. Sorry.

@rsc rsc closed this as completed Jun 25, 2018
@Sherlock-Holo
Copy link
Author

Sherlock-Holo commented Jun 26, 2018 via email

@golang golang locked and limited conversation to collaborators Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants