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: get file path error #52842

Closed
Dami-star opened this issue May 11, 2022 · 2 comments
Closed

net/url: get file path error #52842

Dami-star opened this issue May 11, 2022 · 2 comments

Comments

@Dami-star
Copy link

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

$ go version
go version go1.18.1 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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://mirrors.aliyun.com/goproxy/"
GOROOT="/usr/local/go1.18.1"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go1.18.1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="/usr/local/gcc-12.1.0/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/gosmith/bugReview/template0/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

package main

import (
"fmt"
"net/url"
)

func main() {
u, _ := url.Parse("file:///home/dami/Desktop/%25.txt")
fmt.Println(u.Path)
}

What did you expect to see?

go run main.go
/home/dami/Desktop/%25.txt

What did you see instead?

go run main.go
/home/dami/Desktop/%.txt

@Dami-star Dami-star changed the title affected/package: ner/url: get file path error May 11, 2022
@Dami-star Dami-star changed the title ner/url: get file path error net/url: get file path error May 11, 2022
@ZekeLu
Copy link
Contributor

ZekeLu commented May 11, 2022

%25 is the percent-encoding of %. url.Parse() will unescape %25 to its original form %. So the result is correct.

See https://www.rfc-editor.org/rfc/rfc3986#section-2.4

Because the percent ("%") character serves as the indicator for percent-encoded octets, it must be percent-encoded as "%25" for that octet to be used as data within a URI.

@Dami-star
Copy link
Author

Ok, thanks, if the actual file is %25.txt, the url should be file:///home/dami/Desktop/%2525.txt

@golang golang locked and limited conversation to collaborators May 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants