mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-14 14:18:59 +00:00
client-go/rest: check if url is nil to prevent nil pointer dereference
Signed-off-by: André Martins <aanm90@gmail.com> Kubernetes-commit: 94e7b2b8fdb4028b8b9d10ce57b9b33df146beb7
This commit is contained in:
committed by
Kubernetes Publisher
parent
c501ee0eba
commit
e9d4627252
@@ -519,14 +519,17 @@ func (r Request) finalURLTemplate() url.URL {
|
|||||||
newParams[k] = v
|
newParams[k] = v
|
||||||
}
|
}
|
||||||
r.params = newParams
|
r.params = newParams
|
||||||
url := r.URL()
|
u := r.URL()
|
||||||
|
if u == nil {
|
||||||
|
return url.URL{}
|
||||||
|
}
|
||||||
|
|
||||||
segments := strings.Split(url.Path, "/")
|
segments := strings.Split(u.Path, "/")
|
||||||
groupIndex := 0
|
groupIndex := 0
|
||||||
index := 0
|
index := 0
|
||||||
trimmedBasePath := ""
|
trimmedBasePath := ""
|
||||||
if url != nil && r.c.base != nil && strings.Contains(url.Path, r.c.base.Path) {
|
if r.c.base != nil && strings.Contains(u.Path, r.c.base.Path) {
|
||||||
p := strings.TrimPrefix(url.Path, r.c.base.Path)
|
p := strings.TrimPrefix(u.Path, r.c.base.Path)
|
||||||
if !strings.HasPrefix(p, "/") {
|
if !strings.HasPrefix(p, "/") {
|
||||||
p = "/" + p
|
p = "/" + p
|
||||||
}
|
}
|
||||||
@@ -537,7 +540,7 @@ func (r Request) finalURLTemplate() url.URL {
|
|||||||
groupIndex = 1
|
groupIndex = 1
|
||||||
}
|
}
|
||||||
if len(segments) <= 2 {
|
if len(segments) <= 2 {
|
||||||
return *url
|
return *u
|
||||||
}
|
}
|
||||||
|
|
||||||
const CoreGroupPrefix = "api"
|
const CoreGroupPrefix = "api"
|
||||||
@@ -555,9 +558,9 @@ func (r Request) finalURLTemplate() url.URL {
|
|||||||
// outlet here in case more API groups are added in future if ever possible:
|
// outlet here in case more API groups are added in future if ever possible:
|
||||||
// https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups
|
// https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups
|
||||||
// if a wrong API groups name is encountered, return the {prefix} for url.Path
|
// if a wrong API groups name is encountered, return the {prefix} for url.Path
|
||||||
url.Path = "/{prefix}"
|
u.Path = "/{prefix}"
|
||||||
url.RawQuery = ""
|
u.RawQuery = ""
|
||||||
return *url
|
return *u
|
||||||
}
|
}
|
||||||
// switch segLength := len(segments) - index; segLength {
|
// switch segLength := len(segments) - index; segLength {
|
||||||
switch {
|
switch {
|
||||||
@@ -582,8 +585,8 @@ func (r Request) finalURLTemplate() url.URL {
|
|||||||
segments[index+3] = "{name}"
|
segments[index+3] = "{name}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
url.Path = path.Join(trimmedBasePath, path.Join(segments...))
|
u.Path = path.Join(trimmedBasePath, path.Join(segments...))
|
||||||
return *url
|
return *u
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) tryThrottleWithInfo(ctx context.Context, retryInfo string) error {
|
func (r *Request) tryThrottleWithInfo(ctx context.Context, retryInfo string) error {
|
||||||
|
Reference in New Issue
Block a user