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() enclose IPv6 in square brackets even if host is already in this format #20470

Closed
jleroy opened this issue May 23, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@jleroy
Copy link

commented May 23, 2017

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

go version go1.8.1 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jonathan/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/fb/736129595jl9p0x2nsxx2lmh0000gn/T/go-build264978375=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

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

What did you expect to see?

[[fd41:9eff:c33::1b:ffff]]:5672

What did you see instead?

[fd41:9eff:c33::1b:ffff]:5672

@bradfitz

This comment has been minimized.

Copy link
Member

commented May 23, 2017

Your input is invalid. JoinHostPort expects a host name, which does include square brackets. The square brackets are only valid when joined with a port.

@bradfitz

This comment has been minimized.

Copy link
Member

commented May 23, 2017

Note that JoinHostPort doesn't do any sanitization of your host (e.g. https://play.golang.org/p/cbnk8RrQNy).

The existing docs say exactly what it does:

JoinHostPort combines host and port into a network address of the form "host:port" or, if host
contains a colon or a percent sign, "[host]:port".

I'm not sure there's anything to do here.

@bradfitz bradfitz closed this May 23, 2017

@mikioh mikioh changed the title JoinHostPort() enclose IPv6 in square brackets even if host is already in this format net: JoinHostPort() enclose IPv6 in square brackets even if host is already in this format May 24, 2017

@golang golang locked and limited conversation to collaborators May 24, 2018

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