Skip to content

Commit eb92f3d

Browse files
author
Michael Sullivan
committed
Fix off-by-one error in key/value resolution
Added a test to demonstrate the problem, which yielded this failure in test output: --- FAIL: TestGetPathParamAndPathParams (0.00s) resty_test.go:44: Method: GET resty_test.go:45: Path: /v1/users/[email protected]/100002{details} request_test.go:1838: Expected [true], got [false] request_test.go:1839: Expected [true], got [false] resty_test.go:900: Response Status: 200 OK resty_test.go:901: Response Time: 215.375µs resty_test.go:902: Response Headers: map[Content-Length:[85] Content-Type:[text/plain; charset=utf-8] Date:[Sat, 22 Feb 2025 01:31:45 GMT]] resty_test.go:903: Response Cookies: [] resty_test.go:904: Response Body: TestPathParamURLInput: text response: /v1/users/[email protected]/100002%7Bdetails%7D Once fix was applied, test passed.
1 parent 1e19d6b commit eb92f3d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
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 == 0 || 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])

request_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1827,10 +1827,11 @@ func TestGetPathParamAndPathParams(t *testing.T) {
18271827

18281828
c := dc().
18291829
SetBaseURL(ts.URL).
1830-
SetPathParam("userId", "[email protected]")
1830+
SetPathParam("userId", "[email protected]").
1831+
SetRawPathParam("details", "/details")
18311832

18321833
resp, err := c.R().SetPathParam("subAccountId", "100002").
1833-
Get("/v1/users/{userId}/{subAccountId}/details")
1834+
Get("/v1/users/{userId}/{subAccountId}{details}")
18341835

18351836
assertError(t, err)
18361837
assertEqual(t, http.StatusOK, resp.StatusCode())

0 commit comments

Comments
 (0)