Skip to content

Commit 94e70d3

Browse files
authored
fix: encode path params with BaseURL and the first param at index zero (#781) (#782)
1 parent 37157fa commit 94e70d3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

middleware.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func parseRequestURL(c *Client, r *Request) error {
5757
buf := acquireBuffer()
5858
defer releaseBuffer(buf)
5959
// search for the next or first opened curly bracket
60-
for curr := strings.Index(r.URL, "{"); curr > prev; curr = prev + strings.Index(r.URL[prev:], "{") {
60+
for curr := strings.Index(r.URL, "{"); curr == 0 || curr > prev; curr = prev + strings.Index(r.URL[prev:], "{") {
6161
// write everything from the previous position up to the current
6262
if curr > prev {
6363
buf.WriteString(r.URL[prev:curr])

middleware_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ func Test_parseRequestURL(t *testing.T) {
145145
},
146146
expectedURL: "https://example.com/1/2",
147147
},
148+
{
149+
name: "using base url with path param at index 0",
150+
init: func(c *Client, r *Request) {
151+
c.SetBaseURL("https://example.com/prefix")
152+
r.SetPathParam("first", "1").
153+
SetPathParam("second", "2")
154+
r.URL = "{first}/{second}"
155+
},
156+
expectedURL: "https://example.com/prefix/1/2",
157+
},
148158
{
149159
name: "using BaseURL with absolute URL in request",
150160
init: func(c *Client, r *Request) {

0 commit comments

Comments
 (0)