fasturl: Discard UserInfo

This commit is contained in:
Richard Patel 2018-11-06 00:33:57 +01:00
parent ba9c818461
commit a12bca01c8
No known key found for this signature in database
GPG Key ID: C268B2BBDA2ABECB

View File

@ -360,7 +360,6 @@ func escape(s string, mode encoding) string {
type URL struct { type URL struct {
Scheme Scheme Scheme Scheme
Opaque string // encoded opaque data Opaque string // encoded opaque data
UserInfo string
Host string // host or host:port Host string // host or host:port
Path string // path (relative paths may omit leading slash) Path string // path (relative paths may omit leading slash)
RawPath string // encoded path hint (see EscapedPath method) RawPath string // encoded path hint (see EscapedPath method)
@ -508,7 +507,7 @@ func (u *URL) parse(rawurl string, viaRequest bool) error {
if (u.Scheme != SchemeInvalid || !viaRequest && !strings.HasPrefix(rest, "///")) && strings.HasPrefix(rest, "//") { if (u.Scheme != SchemeInvalid || !viaRequest && !strings.HasPrefix(rest, "///")) && strings.HasPrefix(rest, "//") {
var authority string var authority string
authority, rest = split(rest[2:], "/", false) authority, rest = split(rest[2:], "/", false)
u.UserInfo, u.Host, err = parseAuthority(authority) u.Host, err = parseAuthority(authority)
if err != nil { if err != nil {
return err return err
} }
@ -523,7 +522,7 @@ func (u *URL) parse(rawurl string, viaRequest bool) error {
return nil return nil
} }
func parseAuthority(authority string) (userInfo string, host string, err error) { func parseAuthority(authority string) (host string, err error) {
i := strings.LastIndex(authority, "@") i := strings.LastIndex(authority, "@")
if i < 0 { if i < 0 {
host, err = parseHost(authority) host, err = parseHost(authority)
@ -531,16 +530,16 @@ func parseAuthority(authority string) (userInfo string, host string, err error)
host, err = parseHost(authority[i+1:]) host, err = parseHost(authority[i+1:])
} }
if err != nil { if err != nil {
return "", "", err return "", err
} }
if i < 0 { if i < 0 {
return "", host, nil return host, nil
} }
userinfo := authority[:i] userinfo := authority[:i]
if !validUserinfo(userinfo) { if !validUserinfo(userinfo) {
return "", "", errors.New("fasturl: invalid userinfo") return "", errors.New("fasturl: invalid userinfo")
} }
return userInfo, host, nil return host, nil
} }
// parseHost parses host as an authority without user // parseHost parses host as an authority without user
@ -705,14 +704,10 @@ func (u *URL) String() string {
if u.Opaque != "" { if u.Opaque != "" {
buf.WriteString(u.Opaque) buf.WriteString(u.Opaque)
} else { } else {
if u.Scheme != SchemeInvalid || u.Host != "" || u.UserInfo != "" { if u.Scheme != SchemeInvalid || u.Host != "" {
if u.Host != "" || u.Path != "" || u.UserInfo != "" { if u.Host != "" || u.Path != "" {
buf.WriteString("//") buf.WriteString("//")
} }
if u.UserInfo != "" {
buf.WriteString(u.UserInfo)
buf.WriteByte('@')
}
if h := u.Host; h != "" { if h := u.Host; h != "" {
buf.WriteString(escape(h, encodeHost)) buf.WriteString(escape(h, encodeHost))
} }
@ -923,7 +918,7 @@ func (u *URL) ResolveReference(url *URL, ref *URL) {
if ref.Scheme == SchemeInvalid { if ref.Scheme == SchemeInvalid {
url.Scheme = u.Scheme url.Scheme = u.Scheme
} }
if ref.Scheme != SchemeInvalid || ref.Host != "" || ref.UserInfo != "" { if ref.Scheme != SchemeInvalid || ref.Host != "" {
// The "absoluteURI" or "net_path" cases. // The "absoluteURI" or "net_path" cases.
// We can ignore the error from setPath since we know we provided a // We can ignore the error from setPath since we know we provided a
// validly-escaped path. // validly-escaped path.
@ -931,7 +926,6 @@ func (u *URL) ResolveReference(url *URL, ref *URL) {
return return
} }
if ref.Opaque != "" { if ref.Opaque != "" {
url.UserInfo = ""
url.Host = "" url.Host = ""
url.Path = "" url.Path = ""
return return
@ -941,7 +935,6 @@ func (u *URL) ResolveReference(url *URL, ref *URL) {
} }
// The "abs_path" or "rel_path" cases. // The "abs_path" or "rel_path" cases.
url.Host = u.Host url.Host = u.Host
url.UserInfo = u.UserInfo
url.setPath(resolvePath(u.EscapedPath(), ref.EscapedPath())) url.setPath(resolvePath(u.EscapedPath(), ref.EscapedPath()))
return return
} }