diff --git a/CHANGELOG.md b/CHANGELOG.md index 129d5370c..775b5df11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Prevented browser performance instrumentation from breaking code views when `performance.measure()` returns no value. [#1665](https://github.com/sourcebot-dev/sourcebot/pull/1665) +- Decoded percent-encoded characters in repo names derived from direct generic git URLs. [#1666](https://github.com/sourcebot-dev/sourcebot/pull/1666) ## [5.1.13] - 2026-09-12 diff --git a/packages/backend/src/repoCompileUtils.test.ts b/packages/backend/src/repoCompileUtils.test.ts index df0d90f82..76c0d273b 100644 --- a/packages/backend/src/repoCompileUtils.test.ts +++ b/packages/backend/src/repoCompileUtils.test.ts @@ -334,4 +334,24 @@ describe('compileGenericGitHostConfig_url', () => { const metadata = result[0].metadata as { gitConfig?: Record }; expect(metadata.gitConfig!['zoekt.name']).toBe('github.com/test/repo'); }); + + test('should decode percent-encoded characters in the repo name', async () => { + mockedIsUrlAValidGitRepo.mockResolvedValue(true); + + const config = { + type: 'git' as const, + url: 'https://github.com/test/Project%20Name%20With%20Spaces.git', + }; + + const result = await compileGenericGitHostConfig_url(config, 1); + + expect(result).toHaveLength(1); + // The repo name should have decoded spaces, not %20 + expect(result[0].name).toBe('github.com/test/Project Name With Spaces'); + expect(result[0].displayName).toBe('github.com/test/Project Name With Spaces'); + + const metadata = result[0].metadata as { gitConfig?: Record }; + expect(metadata.gitConfig!['zoekt.name']).toBe('github.com/test/Project Name With Spaces'); + expect(metadata.gitConfig!['zoekt.display-name']).toBe('github.com/test/Project Name With Spaces'); + }); }); diff --git a/packages/backend/src/repoCompileUtils.ts b/packages/backend/src/repoCompileUtils.ts index cdc78d8e0..24483c974 100644 --- a/packages/backend/src/repoCompileUtils.ts +++ b/packages/backend/src/repoCompileUtils.ts @@ -725,7 +725,28 @@ export const compileGenericGitHostConfig_url = async ( // @note: matches the naming here: // https://github.com/sourcebot-dev/zoekt/blob/main/gitindex/index.go#L293 - const repoName = path.join(remoteUrl.host, remoteUrl.pathname.replace(/\.git$/, '')); + // Decode URL-encoded characters (e.g., %20 -> space) to ensure consistent repo names + let decodedPathname: string; + try { + decodedPathname = decodeURIComponent(remoteUrl.pathname); + } catch (e) { + if (e instanceof URIError) { + const warning = `Skipping ${remoteUrl.toString()} - malformed URL encoding.`; + logger.warn(warning); + reportRepositoryDiscoveryIssue({ + code: "INVALID_REPOSITORY_SOURCE", + effect: "TARGET_SKIPPED", + subject: { + kind: "url", + value: remoteUrl.toString(), + }, + message: warning, + }); + return []; + } + throw e; + } + const repoName = path.join(remoteUrl.host, decodedPathname.replace(/\.git$/, '')); const repo: RepoData = { external_codeHostType: 'genericGitHost',