diff --git a/packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts b/packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts index 3447c3a1be2a..2fd05d1dd071 100644 --- a/packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts +++ b/packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts @@ -168,6 +168,30 @@ describe("gitHubApiHostForRemote", () => { ); assert.strictEqual(gitHubApiHostForRemote("git@gitlab.com:a/b.git"), null); }); + + it("ignores a secondary remote whose host is not a valid URL host", () => { + for (const url of [ + "git@nas.08:team/repo.git", + "git@08:team/repo.git", + "git@node.256:team/repo.git", + "git@[2001:db8::1]:team/repo.git", + ]) { + const remotes = [ + "origin\tgit@github.com:pingdotgg/t3code.git (fetch)", + `backup\t${url} (fetch)`, + ].join("\n"); + assert.deepStrictEqual( + resolveGitHubRepository({ + remotes, + resolved: "", + hostHint: undefined, + defaultHost: "github.com", + }), + { host: "github.com", locator: { host: "github.com", owner: "pingdotgg", name: "t3code" } }, + url, + ); + } + }); }); describe("github.com- SSH aliases", () => { diff --git a/packages/source-control-github/src/server/gitHubRepositoryResolution.ts b/packages/source-control-github/src/server/gitHubRepositoryResolution.ts index e42e428d9d99..cfd36b6c0276 100644 --- a/packages/source-control-github/src/server/gitHubRepositoryResolution.ts +++ b/packages/source-control-github/src/server/gitHubRepositoryResolution.ts @@ -166,7 +166,9 @@ function apiHostForSshAlias(host: string): string | null | undefined { export function gitHubApiHostForRemote(remoteUrl: string): string | null { const remote = parseGitRemoteHost(remoteUrl); if (remote === null) return null; - const host = new URL(`https://${remote.host}`).host.toLowerCase(); + const parsed = URL.parse(`https://${remote.host}`); + if (parsed === null) return null; + const host = parsed.host.toLowerCase(); if (isSshRemoteUrl(remoteUrl)) { const aliased = apiHostForSshAlias(host); if (aliased !== undefined) return aliased;