1
0
mirror of https://github.com/golang/go synced 2024-09-24 21:10:12 -06: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:
Scott Lawrence 2010-08-26 13:32:16 -04:00 committed by Russ Cox
parent 25410fc57d
commit 6752ce9331
3 changed files with 30 additions and 1 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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{