Skip to content

fix: percent-encode path parameters in sendRequest - #361

Closed
RaphaelFakhri wants to merge 1 commit into
GetStream:mainfrom
RaphaelFakhri:fix/encode-path-params
Closed

RaphaelFakhri wants to merge 1 commit into
GetStream:mainfrom
RaphaelFakhri:fix/encode-path-params

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Summary

ApiClient.sendRequest substituted path parameters into the URL without encoding them. A value that contains /, ?, # or % changed the request instead of identifying a resource. For example, getMessage({ id: 'a/b' }) requested /messages/a/b, and an id containing # or ? was cut off at that character.

Each value is now encoded with encodeURIComponent before it replaces its {name} token in the path template. Plain ids (letters, digits, -, _) are unchanged. Values with :, such as feed ids, go on the wire as %3A, which is how stream-py (quote(v, safe="")) and getstream-go (url.QueryEscape) already send path parameters.

Testing

__tests__/path-params.test.ts mocks fetch and checks the requested URL for plain values, reserved characters, and several path parameters in one URL. It needs no API credentials.

yarn vitest run __tests__/path-params.test.ts

Prettier and ESLint are clean on the changed files.

Path parameter values were substituted into the URL as-is, so an id containing '/', '?', '#' or '%' changed the request path or was truncated. Each value is now encoded with encodeURIComponent.
@RaphaelFakhri

Copy link
Copy Markdown
Contributor Author

The failing checks are not caused by this change. The integration tests fail with secretOrPrivateKey must have a value because repository secrets are not available to pull requests from forks, and lint fails in the PR title action with Resource not accessible by integration for the same reason. In the same run, the new __tests__/path-params.test.ts passes (3 tests), and so do the other tests that need no credentials.

oliverlaz added a commit that referenced this pull request Nov 13, 2026
## Summary

Regenerates the API clients from the latest server-side spec
(`GetStream/chat` master `7c7ffabb20`) and includes the path-param
encoding fix from #361.

### New endpoints

- Common: `searchAll`
- Moderation: `listAgentFeedback`, `submitAgentFeedback`,
`getAgentReviewStatus`, `countReviewQueue`
- Moderation config versioning: `saveConfigVersion`,
`listConfigVersions`, `getConfigVersion`, `publishConfigVersion`
- `listImports()` now takes an optional request object (backwards
compatible)

### Model changes

30 new interfaces/types. All changes to existing types are additive
(widened unions or new optional fields), for example:

- `ModerationEngineConfig`: `provider` gains `'stream'`, `model` gains
new values, new `reasoning_effort` and `strictness` fields
- `ActivitySelectorType` gains `'friends_engaged'`
- Moderation action types gain `'agent_recommendation'`

### Path params

- `getConfigVersion` / `publishConfigVersion` are the first endpoints
with a numeric path param (`version`, `int32` in the spec).
`ApiClient.sendRequest` now accepts `Record<string, string | number>`
for path params.
- Path param values are now percent-encoded with `encodeURIComponent`
(from #361), so values containing `/`, `?`, `#` or `%` stay within one
path segment. Values with `:` (e.g. feed ids) are sent as `%3A`,
matching stream-py and getstream-go.
- The test from #361 is moved to
`__tests__/integration/path-params.test.ts`, since Vitest only collects
tests from that folder, and gains a numeric-param case.

Supersedes #361.

## Testing

- `yarn build`, `yarn lint` and Prettier are clean
- `yarn test`: 362 passed, 42 skipped

---------

Co-authored-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
@oliverlaz

Copy link
Copy Markdown
Member

Hi @RaphaelFakhri, thank you for your contribution.
I included it in #392 and gave you credit as a co-author.
I'm going to close this PR now

@oliverlaz oliverlaz closed this Nov 13, 2026
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.

2 participants