fix(git): exclude SSH ports from provider URLs (#12537)
This commit is contained in:
1 parent
dd8332da57
commit
29a32660d3
2 files changed
+23
-1
No files matched your search
@@ -110,6 +110,23 @@ describe("detectSourceControlProviderFromRemoteUrl", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not reuse SSH ports for HTTPS provider URLs", () => {
|
||||
expect(
|
||||
detectSourceControlProviderFromRemoteUrl("ssh://[email protected]:24/group/repo.git"),
|
||||
).toEqual({
|
||||
kind: "gitlab",
|
||||
name: "GitLab Self-Hosted",
|
||||
baseUrl: "https://gitlab.example.test",
|
||||
});
|
||||
expect(
|
||||
detectSourceControlProviderFromRemoteUrl("ssh://[email protected]:24/team/project.git"),
|
||||
).toEqual({
|
||||
kind: "unknown",
|
||||
name: "code.example.test",
|
||||
baseUrl: "https://code.example.test",
|
||||
});
|
||||
});
|
||||
|
||||
it("matches self-hosted providers by complete DNS labels", () => {
|
||||
expect(
|
||||
detectSourceControlProviderFromRemoteUrl("https://github.example.com/owner/repo.git")?.kind,
|
||||
|
||||
@@ -146,6 +146,10 @@ export function isSshRemoteUrl(remoteUrl: string): boolean {
|
||||
return SCP_SSH_REMOTE_PATTERN.test(trimmed) || trimmed.toLowerCase().startsWith("ssh://");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the normalized host used for provider detection. SCP-style and SSH remotes return the
|
||||
* hostname only, while other URL schemes retain explicit ports for non-default web endpoints.
|
||||
*/
|
||||
function parseRemoteHost(remoteUrl: string): string | null {
|
||||
const trimmed = remoteUrl.trim();
|
||||
if (trimmed.length === 0) {
|
||||
@@ -158,7 +162,8 @@ function parseRemoteHost(remoteUrl: string): string | null {
|
||||
}
|
||||
|
||||
try {
|
||||
return new URL(trimmed).host.toLowerCase();
|
||||
const url = new URL(trimmed);
|
||||
return (url.protocol === "ssh:" ? url.hostname : url.host).toLowerCase();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user