diff --git a/packages/gittensory-mcp/lib/local-branch.js b/packages/gittensory-mcp/lib/local-branch.js index cfd624173b..ca32023d56 100644 --- a/packages/gittensory-mcp/lib/local-branch.js +++ b/packages/gittensory-mcp/lib/local-branch.js @@ -5,8 +5,14 @@ import { fileURLToPath } from "node:url"; const packageRoot = join(dirname(fileURLToPath(import.meta.url)), ".."); +function stripTrailingSlashes(value) { + let end = value.length; + while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1; + return end === value.length ? value : value.slice(0, end); +} + export function parseGitRemote(remoteUrl) { - const trimmed = String(remoteUrl ?? "").trim().replace(/\/+$/, ""); + const trimmed = stripTrailingSlashes(String(remoteUrl ?? "").trim()); const patterns = [ /^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/, /^https:\/\/github\.com\/([^/]+)\/(.+?)(?:\.git)?$/, diff --git a/test/unit/local-branch.test.ts b/test/unit/local-branch.test.ts index 9fc52aa8c1..0238b24de0 100644 --- a/test/unit/local-branch.test.ts +++ b/test/unit/local-branch.test.ts @@ -1743,6 +1743,8 @@ describe("local MCP git metadata collection", () => { expect(parseGitRemote("git@github.com:entrius/allways-ui.git")).toBe("entrius/allways-ui"); expect(parseGitRemote("https://github.com/JSONbored/gittensory.git")).toBe("JSONbored/gittensory"); expect(parseGitRemote("https://github.com/JSONbored/gittensory/")).toBe("JSONbored/gittensory"); + expect(parseGitRemote("https://github.com/JSONbored/gittensory////")).toBe("JSONbored/gittensory"); + expect(parseGitRemote(`x${"/".repeat(32_000)}x`)).toBeUndefined(); tempDir = mkdtempSync(join(tmpdir(), "gittensory-local-")); git(tempDir, "init");