diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-06-14 13:23:46 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-06-14 13:23:46 +0200 |
commit | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (patch) | |
tree | 9c23734a6ffd4d2a8ac99502eda3cc812a8b130b /src/pkg/net/url | |
parent | 0003ee229fd33ff46cb5f2fe1e35f5c0284debc4 (diff) | |
download | golang-917c5fb8ec48e22459d77e3849e6d388f93d3260.tar.gz |
Imported Upstream version 1.0.2upstream/1.0.2
Diffstat (limited to 'src/pkg/net/url')
-rw-r--r-- | src/pkg/net/url/url.go | 5 | ||||
-rw-r--r-- | src/pkg/net/url/url_test.go | 31 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/pkg/net/url/url.go b/src/pkg/net/url/url.go index b6e79adc2..17bf0d3a3 100644 --- a/src/pkg/net/url/url.go +++ b/src/pkg/net/url/url.go @@ -401,11 +401,12 @@ Error: } func parseAuthority(authority string) (user *Userinfo, host string, err error) { - if strings.Index(authority, "@") < 0 { + i := strings.LastIndex(authority, "@") + if i < 0 { host = authority return } - userinfo, host := split(authority, '@', true) + userinfo, host := authority[:i], authority[i+1:] if strings.Index(userinfo, ":") < 0 { if userinfo, err = unescape(userinfo, encodeUserPassword); err != nil { return diff --git a/src/pkg/net/url/url_test.go b/src/pkg/net/url/url_test.go index d8b253142..75e8abe4e 100644 --- a/src/pkg/net/url/url_test.go +++ b/src/pkg/net/url/url_test.go @@ -188,6 +188,37 @@ var urltests = []URLTest{ }, "http://user:password@google.com", }, + // unescaped @ in username should not confuse host + { + "http://j@ne:password@google.com", + &URL{ + Scheme: "http", + User: UserPassword("j@ne", "password"), + Host: "google.com", + }, + "http://j%40ne:password@google.com", + }, + // unescaped @ in password should not confuse host + { + "http://jane:p@ssword@google.com", + &URL{ + Scheme: "http", + User: UserPassword("jane", "p@ssword"), + Host: "google.com", + }, + "http://jane:p%40ssword@google.com", + }, + { + "http://j@ne:password@google.com/p@th?q=@go", + &URL{ + Scheme: "http", + User: UserPassword("j@ne", "password"), + Host: "google.com", + Path: "/p@th", + RawQuery: "q=@go", + }, + "http://j%40ne:password@google.com/p@th?q=@go", + }, { "http://www.google.com/?q=go+language#foo", &URL{ |