Skip to content

Instantly share code, notes, and snippets.

@JordanMilne
Last active September 13, 2015 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JordanMilne/a68bc9739a3c15969c7b to your computer and use it in GitHub Desktop.
Save JordanMilne/a68bc9739a3c15969c7b to your computer and use it in GitHub Desktop.
URL parsing changes from Go 1.3.3 to 1.5.1
Original: http://example.com/foo/%2F/bar
Scheme: http
Hostname: example.com
Path: /foo///bar
Unparsed: http://example.com/foo///bar
Original: http%3A/%2Fexample.com/baz
Scheme:
Hostname:
Path: http://example.com/baz
Unparsed: http://example.com/baz
Original: http://example.com/foo/%2F/bar
Scheme: http
Hostname: example.com
Path: /foo///bar
Unparsed: http://example.com/foo/%2F/bar
Original: http%3A/%2Fexample.com/baz
Scheme:
Hostname:
Path: http://example.com/baz
Unparsed: http%3A/%2Fexample.com/baz
package main
import "fmt"
import "net/url"
func testUrlParser(toParse string) {
parsed, err := url.Parse(toParse)
if(err != nil) {
panic(err)
}
fmt.Printf("Original: %s\n", toParse)
fmt.Printf("Scheme: %s\n", parsed.Scheme)
fmt.Printf("Hostname: %s\n", parsed.Host)
fmt.Printf("Path: %s\n", parsed.Path)
fmt.Printf("Unparsed: %s\n\n", parsed)
}
func main() {
testUrlParser("http://example.com/foo/%2F/bar")
testUrlParser("http%3A/%2Fexample.com/baz")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment