-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Milestone

Description
The net/url Parse function percent-decodes the path component of the URL. This is a lossy operation. An application cannot distinguish between "/" used as a path segment delimiter and "/" encoded in a path segment. func main() { u, err := url.Parse("http://example.com/x/y%2fz";) if err != nil { panic(err) } fmt.Println(u.Path) } Output: /x/y/z The second "/" is a delimiter. The third "/" is not. An application cannot recover the original encoding of the path from the parsed URL. func main() { u, err := url.Parse("http://example.com/%2b%3f";) if err != nil { panic(err) } fmt.Println(u) } Output: /+? The application cannot determine from the parsed URL that the "+" is percent encoded and that the "?" is percent-encoded in lowercase hex. Scenarios where the information loss is a problem: - The HTTP client in the net/http package cannot request resources with a path segment containing "/". - A server handler for the net/http package cannot implement OAuth 1.0 correctly. In OAuth 1.0, the client signs parts of the request including the raw path. A handler cannot in general verify the signature because the handler cannot get the raw path from the parsed URL. Which compiler are you using (5g, 6g, 8g, gccgo)? 6g Which operating system are you using? Lion Which revision are you using? (hg identify) 9f2be4fbbf69 weekly/weekly.2012-01-20 Please provide any additional information below. Here's how libraries for other languages handle URL path encoding: Python urlparse module: returns raw path Ruby URI module: returns raw path Java URI class: getPath() returns decoded path, getRawPath() returns raw path.