xanzy / go-gitlab

GitLab Go SDK
Apache License 2.0
2.36k stars 934 forks source link

The snippets API was failing due to improper URL encoding of the filename parameter #1878

Closed Sild closed 6 months ago

Sild commented 6 months ago

GitLab api error:

GET https://gitlab.ZZZ.com/api/v4/snippets/YYY/files/HEAD/version 1/raw: 404 {message: 404 File Not Found}'

Root Cause:

The filename contains spaces which need to be properly encoded in the URL path. url.QueryEscape was being used instead of PathEscape.

Resolution:

Use PathEscape when encoding the filename since it is part of the URL path rather than query parameters. After applying this change, the snippets API works correctly.

Please let me know if you have any other questions!