Skip to content

fix: prevent query params from being percent-encoded in API request path#207

Open
davhparry wants to merge 1 commit into
itential:mainfrom
davhparry:fix/api-query-params-double-encoded
Open

fix: prevent query params from being percent-encoded in API request path#207
davhparry wants to merge 1 commit into
itential:mainfrom
davhparry:fix/api-query-params-double-encoded

Conversation

@davhparry

Copy link
Copy Markdown
Contributor

Description

ApiService.request was passing the full URI (including query string) as the request path. url.URL then percent-encoded the '?' as '%3F' in the path while also appending the params via RawQuery, resulting in doubled and malformed query strings. Fix uses u.Path (path only) so params flow through RawQuery exclusively.

Adds ApiService tests that verify params arrive correctly at the server and adds AddHandlerToMux to testlib for request inspection.

Fixes: 175

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Chore

Changes Made

  • ApiService.request was passing the full URI string (e.g. /automation-studio/projects?limit=10) directly as the path field of the client request
  • Go's url.URL treated the ? as a literal path character and percent-encoded it as %3F, while also appending the params via RawQuery — resulting in a malformed, doubled URL like /automation-studio/projects%3Flimit=10?limit=10
  • Fix uses u.Path (path only) so query params flow exclusively through RawQuery

Testing

  • TestApiService_Get_WithQueryParamsInURI — regression test confirming params arrive at the server as a proper query string, not encoded in the path
  • TestApiService_Get_WithMultipleQueryParamsInURI — same for multiple params
  • TestApiService_Delete_WithQueryParamsInURI — same fix applies to DELETE
  • Manually verify ipctl api get '/automation-studio/projects' --params limit=10 returns 200 against a live server

Checklist

  • Code follows the project's style guidelines
  • Self-review of code has been performed
  • Code has been commented where necessary
  • Tested with make setup or relevant profile
  • Commits follow conventional format (type: subject)
  • No secrets or credentials committed
  • Documentation has been updated accordingly
  • PR has been labeled appropriately (enhancement, bug, documentation, refactor, chore)

ApiService.request was passing the full URI (including query string) as
the request path. url.URL then percent-encoded the '?' as '%3F' in the
path while also appending the params via RawQuery, resulting in doubled
and malformed query strings. Fix uses u.Path (path only) so params flow
through RawQuery exclusively.

Adds ApiService tests that verify params arrive correctly at the server
and adds AddHandlerToMux to testlib for request inspection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to pass in query params when making an 'ipctl api get' request.

1 participant