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: String() encodes slash character for file schemes to "%5C" #64872

Closed
tomvladik opened this issue Dec 27, 2023 · 2 comments
Closed

net/url: String() encodes slash character for file schemes to "%5C" #64872

tomvladik opened this issue Dec 27, 2023 · 2 comments

Comments

@tomvladik
Copy link

Go version

go1.21.5 windows/amd64

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

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\tomas.vladik\AppData\Local\go-build
set GOENV=C:\Users\tomas.vladik\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\tomas.vladik\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\tomas.vladik\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.5
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=C:\GIT_tom\Lyra\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\TOMAS~1.VLA\AppData\Local\Temp\go-build907150890=/tmp/go-build -gno-record-gcc-switches

What did you do?

I got piece of code like this:

absolutePath := "c:\test_data\INDEX"
fileURL := url.URL{
Scheme: "file",
Path: absolutePath,
}

url := fileURL.String()

What did you expect to see?

I expect to get url like "file://c:/test_data/INDEX"

What did you see instead?

"file://c:%5Ctest_data%5CINDEX"

which is not valid file URL, I have to use workaround like this

// workaround to get valid file URL
url := strings.Replace(fileURL.String(), "%5C", "/", -1)

@thediveo
Copy link

thediveo commented Dec 27, 2023

I could suspect that the stdlib covers so-called "healthy" file URLs, so you'll need to pass url.URL a Path field with /, not \. But I might mistaken here. What happens when you use url.Parse? At the moment, you'll circumvent the parsing that also handles Path versus RawPath. Judging from an albeit quick look at the sources I would first convert back slashes to forward slashes and then use url.Parse; it looks as if there isn't any support for "legacy" file paths with backslashes. This all looks like a perfect question for the golang-nuts group to get feedback and often useful background information.

@seankhliao
Copy link
Member

I believe this is working as intended, no conversion should be done at stringification, otherwise you wouldn't be able to pass .

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants