Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion packages/backend/src/repoCompileUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,35 @@ describe('compileGenericGitHostConfig_url', () => {

expect(result.repoData).toHaveLength(1);
expect(result.repoData[0].name).toBe('github.com/test/repo');

const metadata = result.repoData[0].metadata as { gitConfig?: Record<string, string> };
expect(metadata.gitConfig!['zoekt.name']).toBe('github.com/test/repo');
});

test('should decode URL-encoded characters in the direct url pathname', async () => {
// Regression for #1384: the file-origin path already calls
// decodeURIComponent on the origin URL pathname, but the direct-URL
// path did not. The same remote configured two different ways
// produced different `name`/`displayName` values, which broke
// search-index metadata and gave the same repo inconsistent
// identifiers depending on how it was configured.
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.repoData).toHaveLength(1);
expect(result.warnings).toHaveLength(0);
// The repo name should have decoded spaces, not %20
expect(result.repoData[0].name).toBe('github.com/test/Project Name With Spaces');
expect(result.repoData[0].displayName).toBe('github.com/test/Project Name With Spaces');

const metadata = result.repoData[0].metadata as { gitConfig?: Record<string, string> };
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');
});
});
8 changes: 7 additions & 1 deletion packages/backend/src/repoCompileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,13 @@ 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) so that a direct URL
// config derives the same repo name as a file-origin config whose origin
// URL gets decoded by the same call below. Without this, a URL like
// `https://github.com/test/Project%20Name.git` and a file config pointing
// at the same remote end up with different `name`/`displayName` values.
const decodedPathname = decodeURIComponent(remoteUrl.pathname);
const repoName = path.join(remoteUrl.host, decodedPathname.replace(/\.git$/, ''));

const repo: RepoData = {
external_codeHostType: 'genericGitHost',
Expand Down