mirror of
https://github.com/golang/go
synced 2024-11-12 05:50:21 -07:00
http: obscure passwords in return value of URL.String
Fixes #974. R=rsc CC=golang-dev https://golang.org/cl/1742057
This commit is contained in:
parent
25410fc57d
commit
6752ce9331
@ -118,6 +118,7 @@ func Get(url string) (r *Response, finalURL string, err os.Error) {
|
||||
if req.URL, err = ParseURL(url); err != nil {
|
||||
break
|
||||
}
|
||||
url = req.URL.String()
|
||||
if r, err = send(&req); err != nil {
|
||||
break
|
||||
}
|
||||
@ -167,6 +168,7 @@ func Head(url string) (r *Response, err os.Error) {
|
||||
if req.URL, err = ParseURL(url); err != nil {
|
||||
return
|
||||
}
|
||||
url = req.URL.String()
|
||||
if r, err = send(&req); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -389,7 +389,12 @@ func (url *URL) String() string {
|
||||
if url.Host != "" || url.Userinfo != "" {
|
||||
result += "//"
|
||||
if url.Userinfo != "" {
|
||||
result += urlEscape(url.Userinfo, false) + "@"
|
||||
// hide the password, if any
|
||||
info := url.Userinfo
|
||||
if i := strings.Index(info, ":"); i >= 0 {
|
||||
info = info[0:i] + ":******"
|
||||
}
|
||||
result += urlEscape(info, false) + "@"
|
||||
}
|
||||
result += url.Host
|
||||
}
|
||||
|
@ -185,6 +185,28 @@ var urltests = []URLTest{
|
||||
},
|
||||
"",
|
||||
},
|
||||
URLTest{
|
||||
"http://user:password@google.com",
|
||||
&URL{
|
||||
Raw: "http://user:password@google.com",
|
||||
Scheme: "http",
|
||||
Authority: "user:password@google.com",
|
||||
Userinfo: "user:password",
|
||||
Host: "google.com",
|
||||
},
|
||||
"http://user:******@google.com",
|
||||
},
|
||||
URLTest{
|
||||
"http://user:longerpass@google.com",
|
||||
&URL{
|
||||
Raw: "http://user:longerpass@google.com",
|
||||
Scheme: "http",
|
||||
Authority: "user:longerpass@google.com",
|
||||
Userinfo: "user:longerpass",
|
||||
Host: "google.com",
|
||||
},
|
||||
"http://user:******@google.com",
|
||||
},
|
||||
}
|
||||
|
||||
var urlnofragtests = []URLTest{
|
||||
|
Loading…
Reference in New Issue
Block a user