-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: StripPrefix does not preserve url path #24366
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
Comments
This has nothing to do with From the documentation -
Regarding EscapedPath(), see -
I don't see anything that needs change here. Everything works according to the documentation. |
In that case, url.EscapedPath() and by association url.String() should be considered unsafe to use if you use the StripPrefix handler and care about the original encoding because those methods will now never return the original encoding. |
Hmm .. on second thoughts I think Because
Whereas
Also, surprisingly, the RawPath vanishes for %20, %21, %22. I have just tested only these though. /cc @bradfitz |
To be honest, maybe this will all be resolved with "worked as expected" because technically everything is behaving as documented. To me, the url's API around I'd also like to understand why |
Change https://golang.org/cl/233637 mentions this issue: |
I stumbled upon this bug just now. @adg's fix looks good to me. Can an approver please take a look? It's a small CL. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.10 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
The
http.StripPrefix
handler doesnt preserve the original path of the request. Specifically, it completely unescapes it, replacing%2F
with/
, for example.It also causes url.Path, url.RawPath, and url.EncodedPath() to become inconsistent with each other.
You can reproduce with the following program:
What did you expect to see?
I expected to see
What did you see instead?
This is the actual output:
So to reiterate, I think EscapePath() should return a version of the path with all the original escaping and I think RawPath should be insync with Path and EscapedPath()
For a comparison, this is what the endpoint that doesnt use StripPrefix outputs:
The text was updated successfully, but these errors were encountered: