diff --git a/middleware.go b/middleware.go index 1fccbb72..603448df 100644 --- a/middleware.go +++ b/middleware.go @@ -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]) diff --git a/middleware_test.go b/middleware_test.go index f5924cbe..49733e95 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -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) {