Skip to content

Commit

Permalink
fix: encode path params with BaseURL and the first param at index zero (
Browse files Browse the repository at this point in the history
  • Loading branch information
sakateka committed Mar 5, 2024
1 parent 37157fa commit 3d91083
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion middleware.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 3d91083

Please sign in to comment.