Skip to content

net/url: paths parsed with a literal space don't properly stringify in a raw way, losing information #38292

@adreed-msft

Description

@adreed-msft

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

$ go version
go version go1.13.4 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/adele/.cache/go-build"
GOENV="/home/adele/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/adele/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build138708956=/tmp/go-build -gno-record-
gcc-switches"

What did you do?

There are certain cases where maintaining whether a character is encoded or not is of utmost importance (for instance, wildcards when referencing object storage solutions).

If a URL has a space in it when parsed, it will succeed at parsing, but it will choose to return the literal path re-encoded, rather than the raw path. (unexpected behavior)

If a URL is completely safely encoded, it will succeed at parsing, and then it will choose to return the raw path. (expected behavior)

Sample below, demonstrating both cases:
https://play.golang.org/p/IeAIos8Wbx-

What did you expect to see?

I expected the complete raw path when stringifying if it's roughly equivalent (in both cases here, it is roughly equivalent).

What did you see instead?

Instead, I got back a encoded literal path, causing a loss of information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions