From 2b62ffd82259eeafd4582b33e1b46d4eebc26a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 13 Mar 2026 09:03:49 +0100 Subject: [PATCH] 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> --- confluence/api.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/confluence/api.go b/confluence/api.go index 9275e9c..48c316c 100644 --- a/confluence/api.go +++ b/confluence/api.go @@ -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 }