Skip to content

fix: preserve trailing slash in SetBaseURL (fixes #1061) - #1191

Open
ObeeJ wants to merge 1 commit into
go-resty:v3from
ObeeJ:fix/setfiles-formdata
Open

fix: preserve trailing slash in SetBaseURL (fixes #1061)#1191
ObeeJ wants to merge 1 commit into
go-resty:v3from
ObeeJ:fix/setfiles-formdata

Conversation

@ObeeJ

@ObeeJ ObeeJ commented Jul 30, 2026

Copy link
Copy Markdown

Summary

SetBaseURL was calling strings.TrimRight(url, "/") which silently dropped a trailing slash. This caused:

client.SetBaseURL("http://host/api/")
client.R().Get("") // hits http://host/api — missing trailing slash

This is a regression of #119 (originally fixed in v1.2).

Fix

  • Store the URL as-is in SetBaseURL — no stripping
  • In URL composition (middleware.go), use strings.TrimRight only when joining with a non-empty request path (to avoid double-slash); use baseURL as-is when the request path is empty or "/"

Test cases covered

baseURL request path result
http://host/api/ "" http://host/api/
http://host/api/ /resource http://host/api/resource
http://host/api /resource http://host/api/resource
http://host/ "" http://host/

Fixes #1061

SetBaseURL was calling strings.TrimRight(url, "/") which silently
dropped a trailing slash. This caused SetBaseURL("http://host/api/")
to resolve empty-path requests to http://host/api instead of
http://host/api/.

Fix:
- Store the URL as-is in SetBaseURL
- In URL composition, use strings.TrimRight only when joining with a
  non-empty request path to avoid double-slash; use baseURL as-is
  when the request path is empty or "/"
- Update the unescape_query_params test expectation to reflect the
  correct URL (trailing slash preserved)
- Add regression test covering empty path, non-empty path, and
  both trailing-slash and non-trailing-slash base URLs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

v3: Regression of #119

1 participant