Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jcaselman opened this issue Oct 7, 2021 · 3 comments
Closed

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

jcaselman opened this issue Oct 7, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@jcaselman
Copy link

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

@seankhliao seankhliao changed the title url/net - RawPath unset even though Path differs from input url/net: RawPath unset even though Path differs from input Oct 8, 2021
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 8, 2021
@seankhliao
Copy link
Member

cc @neild @rsc

@odeke-em odeke-em changed the title url/net: RawPath unset even though Path differs from input net/url: RawPath unset even though Path differs from input Oct 9, 2021
@AlexanderYastrebov
Copy link
Contributor

I think it works as documented
https://pkg.go.dev/net/url#URL.EscapedPath

In general, code should call EscapedPath instead of reading u.RawPath directly.

The EscapedPath returns escaped value in both cases:
https://play.golang.org/p/8eY6NeIrkle

@seankhliao
Copy link
Member

RawPath is only set when it's different from the output of EscapedPath, which is what you should be using. It is documented to only be a hint:

RawPath string // encoded path hint (see EscapedPath method)

Closing as working as intended.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2022
@golang golang locked and limited conversation to collaborators Jul 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants