Closed
Description
RFC 3986 permits percent-encoded characters in the host part of a URL. *net/url.URL.String
will percent-encode the net/URL.Host
field, but confusingly, url.Parse
does not accept URLs produced in this form.
Applications like PostgreSQL that use net/url.Parse
to parse URLs that have this form produce an error, see lib/pq#796. The prior #16127 notes some mismatch between net/url.Parse
and RFC 3986. This issue is around the specific issue of percent-encoded characters in the host, not any larger scope.
What version of Go are you using (go version
)?
$ go version go version go1.12 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE=[redacted] GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH=[redacted] GOPROXY="" GORACE="" GOROOT=[redacted] GOTMPDIR="" GOTOOLDIR=[redacted] GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD=[redacted] CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS=[redacted]
What did you do?
https://play.golang.org/p/l9oOmcNkYUd
What did you expect to see?
URL1: postgres://foo@%2Fvar%2Frun%2Fpostgres/mydb
Host: /var/run/postgres
URL2: postgres://foo@%2Fvar%2Frun%2Fpostgres/mydb
Host: /var/run/postgres
What did you see instead?
URL1: postgres://foo@%2Fvar%2Frun%2Fpostgres/mydb
Host: /var/run/postgres
Parse: parse postgres://foo@%2Fvar%2Frun%2Fpostgres/mydb: invalid URL escape "%2F"