mirror of
https://github.com/golang/go
synced 2024-11-20 04:14:49 -07:00
net/url: better parsing of urls with @ symbol in authority
Fixes #3439 R=r, rsc, dsymonds, n13m3y3r CC=golang-dev https://golang.org/cl/6206090
This commit is contained in:
parent
6a22e2fb3f
commit
f7277dac57
@ -401,11 +401,12 @@ Error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseAuthority(authority string) (user *Userinfo, host string, err 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
|
host = authority
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userinfo, host := split(authority, '@', true)
|
userinfo, host := authority[:i], authority[i+1:]
|
||||||
if strings.Index(userinfo, ":") < 0 {
|
if strings.Index(userinfo, ":") < 0 {
|
||||||
if userinfo, err = unescape(userinfo, encodeUserPassword); err != nil {
|
if userinfo, err = unescape(userinfo, encodeUserPassword); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -188,6 +188,37 @@ var urltests = []URLTest{
|
|||||||
},
|
},
|
||||||
"http://user:password@google.com",
|
"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",
|
"http://www.google.com/?q=go+language#foo",
|
||||||
&URL{
|
&URL{
|
||||||
|
Loading…
Reference in New Issue
Block a user