Conversation
When users configure a GitLab or Azure DevOps connection with a trailing slash in the URL (e.g., https://gitlab.example.com/), the constructed project URLs would have a double slash (https://gitlab.example.com//path) causing 404 errors when opening links. This fix strips trailing slashes from the hostUrl before constructing URLs. Fixes SOU-533 Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
|
Cursor Agent can help with this pull request. Just |
WalkthroughNormalize configured Git host base URLs by stripping trailing slash(es) during resolution across multiple backends (GitLab, GitHub, Gitea, Gerrit, Bitbucket, Azure DevOps, Generic Git Host); add changelog entry documenting the fix for Open in GitLab link double-slash handling. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This comment has been minimized.
This comment has been minimized.
|
@cursor add changelog |
Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/backend/src/repoCompileUtils.ts (1)
64-64: Consider applying trailing-slash normalization consistently to all providers.GitHub (line 64), Gitea (line 245), Gerrit (line 312), and Bitbucket (line 399) lack the same normalization. For those providers, trailing slashes in
hostUrldon't currently produce double-slash URLs (webUrls come from API responses, not string concatenation), but the storedexternal_codeHostUrlwould be inconsistently formatted across providers. Normalizing all providers defensively prevents the same class of bug if URL construction patterns change.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/backend/src/repoCompileUtils.ts` at line 64, The hostUrl for GitHub (const hostUrl = config.url ?? 'https://github.com'), Gitea, Gerrit, and Bitbucket blocks should be normalized the same way as other providers to avoid inconsistent trailing slashes; add or reuse a small helper (e.g., normalizeHostUrl or stripTrailingSlash) and apply it to the hostUrl value in each provider before storing external_codeHostUrl and any URL construction, ensuring the stored external_codeHostUrl has a consistent format across providers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG.md`:
- Line 12: Update the changelog entry that currently references only GitLab (the
line mentioning "Fixed 'Open in GitLab' links... [`#915`]") to also mention Azure
DevOps: state that trailing slashes are stripped from hostUrl for both GitLab
and Azure DevOps (or word it as "Open in GitLab and Azure DevOps links no longer
break when the host URL has a trailing slash"), and keep the PR reference `#915`;
this ensures ADO users can find the fix.
In `@packages/backend/src/repoCompileUtils.ts`:
- Line 163: hostUrl normalization only strips a single trailing slash, so values
like config.url = "https://gitlab.example.com//" can leave a trailing slash and
cause double slashes later; update the hostUrl assignment (the const hostUrl
expression that uses config.url) to strip all trailing slashes by replacing the
current regex with one that matches one-or-more slashes (use /\/+$/) so
concatenation later (e.g., where hostUrl is used at line 169) won’t produce
double slashes.
---
Nitpick comments:
In `@packages/backend/src/repoCompileUtils.ts`:
- Line 64: The hostUrl for GitHub (const hostUrl = config.url ??
'https://github.com'), Gitea, Gerrit, and Bitbucket blocks should be normalized
the same way as other providers to avoid inconsistent trailing slashes; add or
reuse a small helper (e.g., normalizeHostUrl or stripTrailingSlash) and apply it
to the hostUrl value in each provider before storing external_codeHostUrl and
any URL construction, ensuring the stored external_codeHostUrl has a consistent
format across providers.
Changed regex from /\\/$/ to /\\/+$/ to handle cases where there might be multiple trailing slashes in the configured URL. Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/backend/src/repoCompileUtils.ts (1)
90-103: Defensively normalizehostUrlinsidecreateGitHubRepoRecordto prevent external callers from storing un-normalized host URLs.The function is exported and accepts
hostUrlas input. WhilecompileGithubConfignormalizes the URL before calling (line 64), and the hardcoded call inapi.tsuses a normalized URL, the exported function stores the rawhostUrlinexternal_codeHostUrl(line 117) without validation. An external caller could pass a trailing-slash URL that would be stored unchanged.🛡️ Proposed defensive normalization
export const createGitHubRepoRecord = ({ repo, hostUrl, branches, tags, isAutoCleanupDisabled, }: { repo: OctokitRepository, hostUrl: string, ... }) => { - const repoNameRoot = new URL(hostUrl) + const normalizedHostUrl = hostUrl.replace(/\/+$/, ''); + const repoNameRoot = new URL(normalizedHostUrl) .toString() .replace(/^https?:\/\//, '');And replace all subsequent uses of
hostUrlwithin the function body withnormalizedHostUrl.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/backend/src/repoCompileUtils.ts` around lines 90 - 103, createGitHubRepoRecord currently accepts hostUrl and stores it raw into external_codeHostUrl; defensively normalize hostUrl at the start of createGitHubRepoRecord (e.g., construct a URL object from hostUrl and derive a normalized string like url.origin or strip trailing slash) and assign that to a new normalizedHostUrl variable; then replace subsequent uses of hostUrl (including where external_codeHostUrl is set and where repoNameRoot is created) with normalizedHostUrl so callers cannot store an un-normalized URL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@packages/backend/src/repoCompileUtils.ts`:
- Line 64: The trailing-slash normalization for hostUrl is already corrected to
use .replace(/\/+$/, ''); no code changes required—just verify all occurrences
of the hostUrl assignment in repoCompileUtils.ts (the const hostUrl
declarations) consistently use .replace(/\/+$/, '') across the referenced spots
(lines noted in the review) and keep them unchanged.
---
Nitpick comments:
In `@packages/backend/src/repoCompileUtils.ts`:
- Around line 90-103: createGitHubRepoRecord currently accepts hostUrl and
stores it raw into external_codeHostUrl; defensively normalize hostUrl at the
start of createGitHubRepoRecord (e.g., construct a URL object from hostUrl and
derive a normalized string like url.origin or strip trailing slash) and assign
that to a new normalizedHostUrl variable; then replace subsequent uses of
hostUrl (including where external_codeHostUrl is set and where repoNameRoot is
created) with normalizedHostUrl so callers cannot store an un-normalized URL.


Stripped trailing slashes from
hostUrlfor GitLab and Azure DevOps to fix invalid "Open in GitLab" links.The issue occurred when
hostUrlwas configured with a trailing slash, leading to a double slash in the generated URL and subsequent 404 errors. This change ensures URLs are correctly formed.Linear Issue: SOU-533
Summary by CodeRabbit