Skip to content

Commit d034440

Browse files
inayayousfijuliusmarminge
authored andcommitted
fix(client-runtime): treat a numeric segment as a port only behind the host
A port can only sit directly behind the authority, but the guard rejected any all-numeric last segment of a hosted URL. A repository genuinely named with digits, as in https://github.com/acme/123, proposed no folder. The port rule now applies only when nothing follows the numeric segment. Deeper segments are path, so acme/123 keeps proposing 123.
1 parent 6888fe8 commit d034440

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/client-runtime/src/operations/projects.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ describe("add project shared logic", () => {
6060
expect(getCloneDirectoryName(" https://github.com/owner/repo.git ")).toBe("repo");
6161
});
6262

63+
it("keeps a numeric repository name that sits on a path", () => {
64+
expect(getCloneDirectoryName("https://github.com/acme/123.git")).toBe("123");
65+
expect(getCloneDirectoryName("https://github.com/acme/123")).toBe("123");
66+
expect(getCloneDirectoryName("[email protected]:acme/123.git")).toBe("123");
67+
});
68+
6369
it("proposes no clone folder for a link that names no repository", () => {
6470
expect(getCloneDirectoryName("https://github.com/")).toBe("");
6571
expect(getCloneDirectoryName("https://github.com")).toBe("");

‎packages/client-runtime/src/operations/projects.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ export function getCloneDirectoryName(repositoryOrRemoteUrl: string | null | und
198198
}
199199

200200
const lastSegment = segments.at(-1)?.trim() ?? "";
201-
if (hasHost && /^\d+$/.test(lastSegment)) {
201+
// A port can only sit directly behind the authority, so it is a port only
202+
// when nothing follows it. Deeper segments are path, even when numeric: the
203+
// repository in `https://host/acme/123` really is named `123`.
204+
if (hasHost && segments.length === 2 && /^\d+$/.test(lastSegment)) {
202205
return "";
203206
}
204207
return lastSegment.endsWith(".git") ? lastSegment.slice(0, -".git".length) : lastSegment;

0 commit comments

Comments
 (0)