URL-encoded IDs are double encoding, returning incorrect 404 errors
Bug Report
Starting with version 1.25, the Golang Gitlab client is double encoding IDs that are specified with a URL encoding format. EG, an identifier provided as my/project is being URL encoded once as my%2Fproject, and then encoding the percent sign again to form an ID of my%252Fproject. This appears to coincide with the refactor in this commit: b365db4b
Relevant Code
This can be reproduced with a code snippet as follows:
package main
import (
"log"
"net/http"
"github.com/hashicorp/go-retryablehttp"
gitlab "gitlab.com/gitlab-org/api/client-go"
)
func main() {
client, err := gitlab.NewClient(
"PAT",
gitlab.WithRequestLogHook(func(l retryablehttp.Logger, r *http.Request, i int) {
log.Printf("%s", r.URL)
}),
)
if err != nil {
log.Fatalf("failed to init %s", err)
}
// Err will be present
_, _, err = client.Namespaces.GetNamespace("my/namespace")
}
Versions of 1.24 and below show the correct URL, while versions >= 1.25 show a double encoded link:
1.24 Correct behavior - see Go Playground link:
2026/02/05 16:28:00 https://gitlab.com/api/v4/namespaces/my%2Fnamespace
2026/02/05 16:28:00 https://gitlab.com/api/v4/namespaces/my%2Fnamespace
2026/02/05 16:28:02 https://gitlab.com/api/v4/namespaces/my%2Fnamespace
2026/02/05 16:28:04 https://gitlab.com/api/v4/namespaces/my%2Fnamespace
2026/02/05 16:28:08 https://gitlab.com/api/v4/namespaces/my%2Fnamespace
2026/02/05 16:28:12 https://gitlab.com/api/v4/namespaces/my%2Fnamespace
Versions from 1.25 on are being double encoded:
1.25 Incorrect behavior, see Go Playground Link
2026/02/05 16:30:56 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:30:57 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:30:59 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:31:02 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:31:05 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:31:09 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
Reproducible to latest version, v1.28: https://goplay.tools/snippet/ENGzlXm7jfQ
Relevant Log Output
These are the logs that are shown when logging the outgoing request URL when using the Get Namespaces API:
2026/02/05 16:30:56 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:30:57 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:30:59 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:31:02 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:31:05 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
2026/02/05 16:31:09 https://gitlab.com/api/v4/namespaces/my%252Fnamespace
Additional Details
- GitLab Client Go Version:
1.25 - GitLab Instance Version: Doesn't matter
- Go Version: v1.25
- License Tier: We use Ultimate, but it is reproducible across envs
Edited by 🤖 GitLab Bot 🤖