-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: document that Parse unescapes paths #3659
Labels
Milestone
Comments
The RFC and the Go API are at odds here: if r.URL.Path is a single string, then there is no way to represent %2f as different from /, since the path is already decoded. We can't just leave the %2f, because /%2f is what you get from decoding /%252f. Short of making the Path a []string (which would be much less convenient for the vast majority of code), there's no fix. Thankfully, very few apps choose to assign special meaning to path elements containing %2f characters (this pretty much only comes up during OAuth). If your app needs to assign special meaning, the server can reprocess req.RequestURI as it sees fit, and the client can issue requests using &url.URL{Opaque: rawURI}. See also issue #2782. Russ Status changed to Unfortunate. |
Issue #4732 has been merged into this issue. |
This issue was closed by revision 4085426. Status changed to Fixed. |
The cleanPath is applied to r.URL.Path. So /%2f is unescaped to //, and cleanPath turns it to /. Then a redirect is responsed. If cleanPath applies to r.RequestURI's path part, there is no change to cleanPath("/%2f"). So no redirect happened. The handler matches "//"(r.URL.Path) is called. When the path is "//", it is redirected to "/" and not passed to the handler, the same as before. |
Issue #6658 has been merged into this issue. |
rsc
added a commit
that referenced
this issue
Jun 22, 2015
Historically we have declined to try to provide real support for URLs that contain %2F in the path, but they seem to be popping up more often, especially in (arguably ill-considered) REST APIs that shoehorn entire paths into individual path elements. The obvious thing to do is to introduce a URL.RawPath field that records the original encoding of Path and then consult it during URL.String and URL.RequestURI. The problem with the obvious thing is that it breaks backward compatibility: if someone parses a URL into u, modifies u.Path, and calls u.String, they expect the result to use the modified u.Path and not the original raw encoding. Split the difference by treating u.RawPath as a hint: the observation is that there are many valid encodings of u.Path. If u.RawPath is one of them, use it. Otherwise compute the encoding of u.Path as before. If a client does not use RawPath, the only change will be that String selects a different valid encoding sometimes (the original passed to Parse). This ensures that, for example, HTTP requests use the exact encoding passed to http.Get (or http.NewRequest, etc). Also add new URL.EscapedPath method for access to the actual escaped path. Clients should use EscapedPath instead of reading RawPath directly. All the old workarounds remain valid. Fixes #5777. Might help #9859. Fixes #7356. Fixes #8767. Fixes #8292. Fixes #8450. Fixes #4860. Fixes #10887. Fixes #3659. Fixes #8248. Fixes #6658. Reduces need for #2782. Change-Id: I77b88f14631883a7d74b72d1cf19b0073d4f5473 Reviewed-on: https://go-review.googlesource.com/11302 Reviewed-by: Brad Fitzpatrick <[email protected]>
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by lijie.wong:
The text was updated successfully, but these errors were encountered: