Skip to content

Encode IDs when building request paths - #186

Merged
anubhav-intercom merged 1 commit into
masterfrom
encode-path-segments
Oct 7, 2026
Merged

anubhav-intercom merged 1 commit into
masterfrom
encode-path-segments

Conversation

@anubhav-intercom

@anubhav-intercom anubhav-intercom commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Why?

IDs passed to the client go into the request path unchanged. An ID containing /, ? or # changes which URL is requested (42?per_page=10 fetches user 42 with an extra query string), and . or .. are treated as relative path segments.

How?

Each ID is now encoded as a single path segment, and an empty, . or .. ID is rejected with an error.

Test run

The repo has no CI, so the unit tests were run once through a temporary workflow (run): 78 of 78 pass, and the 3 new tests fail against master's library code. That workflow commit has been dropped from this branch.

Generated with Claude Code

IDs passed to the resource clients were concatenated into the request
path as-is, so values containing '/', '?', '#' or '%' changed the
requested URL, and '.' or '..' were resolved as relative segments.

Add Client.EncodePathSegment, which escapes the ID as a single path
segment and rejects empty, '.' and '..' IDs, and use it wherever an ID
is part of a resource path.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@anubhav-intercom
anubhav-intercom marked this pull request as ready for review October 6, 2026 16:26
@anubhav-intercom
anubhav-intercom merged commit 48f6acc into master Oct 7, 2026
3 checks passed
@anubhav-intercom
anubhav-intercom deleted the encode-path-segments branch October 7, 2026 10:46
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