mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-17 07:57:37 +08:00
confluence: fix NewAPI double-slash and DeletePageLabel missing status check
NewAPI: normalize baseURL by trimming the trailing slash before building rest and json-rpc endpoints. Previously the TrimSuffix only applied to api.BaseURL but rest/json URLs were already constructed with the raw (potentially trailing-slash) baseURL, producing double slashes like 'http://example.com//rest/api'. DeletePageLabel: add a non-200/non-204 status check before the type assertion. Without this guard any error response (400, 403, 500) would fall through to request.Response.(*LabelInfo) and either panic or return garbage data. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
807d057f7b
commit
2b62ffd822
@ -108,6 +108,9 @@ func NewAPI(baseURL string, username string, password string, insecureSkipVerify
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize baseURL once before building all derived endpoints.
|
||||
baseURL = strings.TrimSuffix(baseURL, "/")
|
||||
|
||||
var httpClient *http.Client
|
||||
if insecureSkipVerify {
|
||||
httpClient = &http.Client{
|
||||
@ -137,7 +140,7 @@ func NewAPI(baseURL string, username string, password string, insecureSkipVerify
|
||||
return &API{
|
||||
rest: rest,
|
||||
json: json,
|
||||
BaseURL: strings.TrimSuffix(baseURL, "/"),
|
||||
BaseURL: baseURL,
|
||||
}
|
||||
}
|
||||
|
||||
@ -665,6 +668,10 @@ func (api *API) DeletePageLabel(page *PageInfo, label string) (*LabelInfo, error
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if request.Raw.StatusCode != http.StatusOK {
|
||||
return nil, newErrorStatusNotOK(request)
|
||||
}
|
||||
|
||||
return request.Response.(*LabelInfo), nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user