-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Description
What version of Go are you using (go version)?
go version go1.8 linux/amd64
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/work:/opt/google/cloud-sdk/platform/google_appengine/goroot/src"
GORACE=""
GOROOT="/opt/google/go"
GOTOOLDIR="/opt/google/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build015435601=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
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/qbW1wWkcKY
What did you expect to see?
I would expect both URLs in the example code to be parsed the same way, and more importantly that the scheme for both is empty (and inherently IsAbs returning false for both).
What did you see instead?
The hostname in the second url was interpreted as the scheme and the port number as opaque. This causes IsAbs to return true. This makes IsAbs unsuitable to actually figure out if there's a scheme specified or not in some user input.
Although it's debatable whether example.com from example.com:80 can be interpreted as a scheme, I think it's not the intuitive choice. Alternatively I'd appreciate a way to check for "conventional" scheme's being present without having to so a strings.Contains("://") manually.