Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: encode path params with BaseURL and the first param at index zero (#781) #782

Merged
merged 1 commit into from Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion middleware.go
Expand Up @@ -57,7 +57,7 @@ func parseRequestURL(c *Client, r *Request) error {
buf := acquireBuffer()
defer releaseBuffer(buf)
// search for the next or first opened curly bracket
for curr := strings.Index(r.URL, "{"); curr > prev; curr = prev + strings.Index(r.URL[prev:], "{") {
for curr := strings.Index(r.URL, "{"); curr == 0 || curr > prev; curr = prev + strings.Index(r.URL[prev:], "{") {
// write everything from the previous position up to the current
if curr > prev {
buf.WriteString(r.URL[prev:curr])
Expand Down
10 changes: 10 additions & 0 deletions middleware_test.go
Expand Up @@ -145,6 +145,16 @@ func Test_parseRequestURL(t *testing.T) {
},
expectedURL: "https://example.com/1/2",
},
{
name: "using base url with path param at index 0",
init: func(c *Client, r *Request) {
c.SetBaseURL("https://example.com/prefix")
r.SetPathParam("first", "1").
SetPathParam("second", "2")
r.URL = "{first}/{second}"
},
expectedURL: "https://example.com/prefix/1/2",
},
{
name: "using BaseURL with absolute URL in request",
init: func(c *Client, r *Request) {
Expand Down