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: export escaper with mode encodePath #36102
Comments
I'm not sure I understand. If |
Because the Lines 119 to 123 in 7d30af8
Here, For example, if we have a static file server: package main
import "net/http"
func main() {
http.Handle("/", http.FileServer(http.Dir(".")))
http.ListenAndServe(":1234", nil)
} Let's cURL it: $ curl localhost:1234
<pre>
<a href="a%3F/">a?/</a>
<a href="server.go">server.go</a>
</pre> Note that
While I'm manually rendering an HTML page. |
/cc @bradfitz |
The URL.EscapedPath method already does what you want: https://play.golang.org/p/cOFqKqyM88y fmt.Println((&url.URL{Path: "/This is/a path/?foo=bar"}).EscapedPath())
(The implementation of EscapedPath is basically just Given what a fringe use case this is, I don't think we want to add a top-level func for this. |
@bradfitz So, you are saying that |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It does.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Use
url.PathEscape
to escape file system path.Notice that
?
is a valid path character on Unix-like systems.Don't we treat it as a query that follows.
What did you expect to see?
What did you see instead?
Why?
PathEscape
is actually the path segment escaper.What I need is a path escaper, with
mode == encodePath
, notencodePathSegment
. Something like:Workarounds
escape path segments individually
use
EscapedPath
The text was updated successfully, but these errors were encountered: