fix: normalize trailing slashes in serverURL#5
Conversation
…I endpoints The constructor now normalizes serverURL by trimming trailing slashes, preventing the dreaded double-slash debacle (https://coder.test//api/...) that makes URLs look like they've had one too many drinks.
|
ready for review |
There was a problem hiding this comment.
Pull request overview
Normalizes the Coder deployment base URL used by RealCoderClient to avoid generating double-slash API URLs when a user provides a trailing slash, and adds a regression test to cover this input case.
Changes:
- Strip trailing slashes from
serverURLinRealCoderClient’s constructor before building request URLs. - Add a unit test ensuring a trailing-slash
serverURLstill produces correct API URLs. - Regenerate
dist/index.jsto include the runtime change in the shipped GitHub Action bundle.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coder-client.ts | Normalizes serverURL by removing trailing slashes before constructing request URLs. |
| src/coder-client.test.ts | Adds coverage for trailing-slash serverURL behavior when creating chats. |
| dist/index.js | Updates the compiled action bundle to reflect the source change (and includes additional bundler-output changes). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mafredri
left a comment
There was a problem hiding this comment.
🤖 Agent on behalf of mafredri
Zero concerns, LGTM. The /\/+$/ regex handles both single and multiple trailing slashes. Test correctly verifies the constructed URL has no double-slash.
Clean refactor from private readonly parameter property to explicit assignment in the constructor body. The behavioral change is one line.
One regex to strip them all, one test to find them. Slash-free since 2026.
Dismissing erroneous APPROVE. Agent should have used COMMENT, not APPROVE.
|
Brought into main via #29 (with attribution). Closing. 🤖 This comment was created with the help of Coder Agents. |
…ning Three pre-v0 hardening fixes originally proposed by @johnstcn in #5, #6, and #7. Closes those in favor of this single follow-up. * `RealCoderClient` constructor normalizes trailing slashes on the `coder-url` input so concatenated API URLs cannot double-slash. `normalizeBaseUrl` extracted to `src/url.ts` (no module cycle). * `githubToken` schema rejects empty strings (`.min(1)`), matching `coderToken`. * `getCoderUserByGitHubId` calls `request<unknown>` (was `<unknown[]>`) to match the `{ users: [...] }` response shape it parses. * `existing-chat-id` is now `ChatIdSchema.parse`-ed at runtime instead of a `as ChatId` cast. * `GITHUB_URL_REGEX` anchored at the tail so URLs with extra path segments are rejected; query strings and fragments still accepted. * Drop the redundant `process.exit(1)` after `core.setFailed(...)`. 🤖 Authored by Coder Agents.
serverURLin theRealCoderClientconstructor to prevent double-slash API URLs