From 638a021f9a7016bc55d51d6af1e678e61f233ad7 Mon Sep 17 00:00:00 2001 From: Tyagiquamar Date: Thu, 17 Sep 2026 22:35:46 +0530 Subject: [PATCH 1/3] fix(backend): decode percent-encoded characters in generic git URL repo names --- packages/backend/src/repoCompileUtils.test.ts | 20 +++++++++++++++++++ packages/backend/src/repoCompileUtils.ts | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) 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..de529776c 100644 --- a/packages/backend/src/repoCompileUtils.ts +++ b/packages/backend/src/repoCompileUtils.ts @@ -725,7 +725,9 @@ 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 + const decodedPathname = decodeURIComponent(remoteUrl.pathname); + const repoName = path.join(remoteUrl.host, decodedPathname.replace(/\.git$/, '')); const repo: RepoData = { external_codeHostType: 'genericGitHost', From 55f8c54a42daf14d1296f2714fc6382f00c1533e Mon Sep 17 00:00:00 2001 From: Tyagiquamar Date: Thu, 17 Sep 2026 22:36:57 +0530 Subject: [PATCH 2/3] chore: add CHANGELOG entry for #1666 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d67263859..b4e09431c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [EE] Fixed missing account-linking prompts during OAuth authorization and restored prompts when new optional providers are configured. [#1663](https://github.com/sourcebot-dev/sourcebot/pull/1663) - Prevented browser performance instrumentation from breaking code views when `performance.measure()` returns no value. [#1665](https://github.com/sourcebot-dev/sourcebot/pull/1665) - Added specific authentication error messages and recovery guidance shared by the login form and error page. [#1669](https://github.com/sourcebot-dev/sourcebot/pull/1669) +- 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 From 88aec56d0c339e0da423b4523d4d4e6542c49847 Mon Sep 17 00:00:00 2001 From: Tyagiquamar Date: Fri, 18 Sep 2026 12:30:18 +0530 Subject: [PATCH 3/3] fix(backend): catch URIError in decodeURIComponent when parsing generic Git URL --- packages/backend/src/repoCompileUtils.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/repoCompileUtils.ts b/packages/backend/src/repoCompileUtils.ts index de529776c..24483c974 100644 --- a/packages/backend/src/repoCompileUtils.ts +++ b/packages/backend/src/repoCompileUtils.ts @@ -726,7 +726,26 @@ export const compileGenericGitHostConfig_url = async ( // @note: matches the naming here: // https://github.com/sourcebot-dev/zoekt/blob/main/gitindex/index.go#L293 // Decode URL-encoded characters (e.g., %20 -> space) to ensure consistent repo names - const decodedPathname = decodeURIComponent(remoteUrl.pathname); + 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 = {