Skip to content

Commit 72bf159

Browse files
fix(backend): decode percent-encoded characters in generic git URL repo names (#1666)
* fix(backend): decode percent-encoded characters in generic git URL repo names * chore: add CHANGELOG entry for #1666 * fix(backend): catch URIError in decodeURIComponent when parsing generic Git URL * Remove duplicate changelog entry for decoding URLs Removed duplicate entry for decoding percent-encoded characters in repo names. --------- Co-authored-by: Tyagiquamar <Tyagiquamar@users.noreply.github.com> Co-authored-by: Brendan Kellam <brendan@sourcebot.dev> Co-authored-by: Brendan Kellam <bshizzle1234@gmail.com>
1 parent f6b6a4a commit 72bf159

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Upgraded `engine.io` to `^6.6.11`, `source-map-js` to `^1.2.2`, `smol-toml` to `^1.9.0`, `fast-copy` to `^3.1.0`, and `dompurify` to `^3.4.16`. [#1714](https://github.com/sourcebot-dev/sourcebot/pull/1714)
2121
- Upgraded `golang.org/x/crypto` to `v0.56.0` and OpenTelemetry-Go exporters and SDK to `v1.45.0` in Zoekt. [#1716](https://github.com/sourcebot-dev/sourcebot/pull/1716)
2222
- Upgraded `@modelcontextprotocol/sdk` to `^1.32.1`. [#1719](https://github.com/sourcebot-dev/sourcebot/pull/1719)
23+
- Decoded percent-encoded characters in repo names derived from direct generic git URLs. [#1666](https://github.com/sourcebot-dev/sourcebot/pull/1666)
2324
- Fixed `.gitattributes` `linguist-language` overrides being ignored for files in subdirectories. [#1692](https://github.com/sourcebot-dev/sourcebot/pull/1692)
2425

2526
## [5.1.15] - 2026-09-29

‎packages/backend/src/repoCompileUtils.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,24 @@ describe('compileGenericGitHostConfig_url', () => {
334334
const metadata = result[0].metadata as { gitConfig?: Record<string, string> };
335335
expect(metadata.gitConfig!['zoekt.name']).toBe('github.com/test/repo');
336336
});
337+
338+
test('should decode percent-encoded characters in the repo name', async () => {
339+
mockedIsUrlAValidGitRepo.mockResolvedValue(true);
340+
341+
const config = {
342+
type: 'git' as const,
343+
url: 'https://github.com/test/Project%20Name%20With%20Spaces.git',
344+
};
345+
346+
const result = await compileGenericGitHostConfig_url(config, 1);
347+
348+
expect(result).toHaveLength(1);
349+
// The repo name should have decoded spaces, not %20
350+
expect(result[0].name).toBe('github.com/test/Project Name With Spaces');
351+
expect(result[0].displayName).toBe('github.com/test/Project Name With Spaces');
352+
353+
const metadata = result[0].metadata as { gitConfig?: Record<string, string> };
354+
expect(metadata.gitConfig!['zoekt.name']).toBe('github.com/test/Project Name With Spaces');
355+
expect(metadata.gitConfig!['zoekt.display-name']).toBe('github.com/test/Project Name With Spaces');
356+
});
337357
});

‎packages/backend/src/repoCompileUtils.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,28 @@ export const compileGenericGitHostConfig_url = async (
725725

726726
// @note: matches the naming here:
727727
// https://github.com/sourcebot-dev/zoekt/blob/main/gitindex/index.go#L293
728-
const repoName = path.join(remoteUrl.host, remoteUrl.pathname.replace(/\.git$/, ''));
728+
// Decode URL-encoded characters (e.g., %20 -> space) to ensure consistent repo names
729+
let decodedPathname: string;
730+
try {
731+
decodedPathname = decodeURIComponent(remoteUrl.pathname);
732+
} catch (e) {
733+
if (e instanceof URIError) {
734+
const warning = `Skipping ${remoteUrl.toString()} - malformed URL encoding.`;
735+
logger.warn(warning);
736+
reportRepositoryDiscoveryIssue({
737+
code: "INVALID_REPOSITORY_SOURCE",
738+
effect: "TARGET_SKIPPED",
739+
subject: {
740+
kind: "url",
741+
value: remoteUrl.toString(),
742+
},
743+
message: warning,
744+
});
745+
return [];
746+
}
747+
throw e;
748+
}
749+
const repoName = path.join(remoteUrl.host, decodedPathname.replace(/\.git$/, ''));
729750

730751
const repo: RepoData = {
731752
external_codeHostType: 'genericGitHost',

0 commit comments

Comments
 (0)