Skip to content

net/url: Parse does not permit percent escapes in host #30844

Closed
@zombiezen

Description

@zombiezen

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.SuggestedIssues that may be good for new contributors looking for work to do.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions