Skip to content

net/url: RawPath unset even though Path differs from input #48854

@jcaselman

Description

@jcaselman

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

$ go version
go version go1.16 darwin/amd64

Does this issue reproduce with the latest release?

✔️

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/caselman/Library/Caches/go-build"
GOENV="/Users/caselman/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/caselman/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/caselman/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/caselman/code/goepf/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t9/cyl4762s64d7mcb1zg67yt1r0000gn/T/go-build1746458354=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://play.golang.org/p/RTw-u_iiYfK

package main

import (
	"fmt"
	"net/url"
)

func main() {
	a,_ := url.Parse("file:///some%20path")
	fmt.Println(a.Path, a.RawPath)

	b,_ := url.Parse("file:///some%2Fpath")
	fmt.Println(b.Path, b.RawPath)

}

What did you expect to see?

/some path /some%20path
/some/path /some%2Fpath

What did you see instead?

/some path 
/some/path /some%2Fpath

I did not expect RawPath to be unset in the first case, when the value set in Path is different than the input to setPath

Wondering if https://github.com/golang/go/blob/master/src/net/url/url.go#L669 is meant to be:

if escp := escape(p, encodePath); p == escp {

and if not, why the discrepancy based on the input path containing a %20 vs a %2F?

Thanks

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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions