url.go (go1.19.src) | : | url.go (go1.19.1.src) | ||
---|---|---|---|---|
skipping to change at line 1194 | skipping to change at line 1194 | |||
return err | return err | |||
} | } | |||
*u = *u1 | *u = *u1 | |||
return nil | return nil | |||
} | } | |||
// JoinPath returns a new URL with the provided path elements joined to | // JoinPath returns a new URL with the provided path elements joined to | |||
// any existing path and the resulting path cleaned of any ./ or ../ elements. | // any existing path and the resulting path cleaned of any ./ or ../ elements. | |||
// Any sequences of multiple / characters will be reduced to a single /. | // Any sequences of multiple / characters will be reduced to a single /. | |||
func (u *URL) JoinPath(elem ...string) *URL { | func (u *URL) JoinPath(elem ...string) *URL { | |||
url := *u | elem = append([]string{u.EscapedPath()}, elem...) | |||
if len(elem) > 0 { | var p string | |||
elem = append([]string{u.EscapedPath()}, elem...) | if !strings.HasPrefix(elem[0], "/") { | |||
p := path.Join(elem...) | // Return a relative path if u is relative, | |||
// path.Join will remove any trailing slashes. | // but ensure that it contains no ../ elements. | |||
// Preserve at least one. | elem[0] = "/" + elem[0] | |||
if strings.HasSuffix(elem[len(elem)-1], "/") && !strings.HasSuffi | p = path.Join(elem...)[1:] | |||
x(p, "/") { | } else { | |||
p += "/" | p = path.Join(elem...) | |||
} | } | |||
url.setPath(p) | // path.Join will remove any trailing slashes. | |||
// Preserve at least one. | ||||
if strings.HasSuffix(elem[len(elem)-1], "/") && !strings.HasSuffix(p, "/" | ||||
) { | ||||
p += "/" | ||||
} | } | |||
url := *u | ||||
url.setPath(p) | ||||
return &url | return &url | |||
} | } | |||
// validUserinfo reports whether s is a valid userinfo string per RFC 3986 | // validUserinfo reports whether s is a valid userinfo string per RFC 3986 | |||
// Section 3.2.1: | // Section 3.2.1: | |||
// | // | |||
// userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) | // userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) | |||
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" | // unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" | |||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")" | // sub-delims = "!" / "$" / "&" / "'" / "(" / ")" | |||
// / "*" / "+" / "," / ";" / "=" | // / "*" / "+" / "," / ";" / "=" | |||
End of changes. 2 change blocks. | ||||
11 lines changed or deleted | 17 lines changed or added |