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

Comments

Projects
None yet
5 participants
@Sherlock-Holo
Copy link

commented Jun 22, 2018

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

This comment has been minimized.

Copy link
Member

commented Jun 22, 2018

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 this to the Unplanned milestone Jun 22, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2018

CC @mikioh

@Sherlock-Holo

This comment has been minimized.

Copy link
Author

commented Jun 22, 2018

@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

This comment has been minimized.

Copy link
Author

commented Jun 22, 2018

@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

This comment has been minimized.

Copy link
Member

commented Jun 22, 2018

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

This comment has been minimized.

Copy link
Author

commented Jun 22, 2018

@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

This comment has been minimized.

Copy link
Member

commented Jun 22, 2018

@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

This comment has been minimized.

Copy link
Author

commented Jun 22, 2018

@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

This comment has been minimized.

Copy link
Member

commented Jun 22, 2018

@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

This comment has been minimized.

Copy link
Author

commented Jun 22, 2018

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

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jun 22, 2018

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

@Sherlock-Holo

This comment has been minimized.

Copy link
Author

commented Jun 22, 2018

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

This comment has been minimized.

Copy link
Contributor

commented Jun 25, 2018

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

@rsc rsc closed this Jun 25, 2018

@Sherlock-Holo

This comment has been minimized.

Copy link
Author

commented Jun 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.