Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: normalize trailing slash in git remote URLs (#16536)

mikemikimike6699fc95dc5d
diff --git a/__tests__/utils/parse-git-remote-url.test.ts b/__tests__/utils/parse-git-remote-url.test.ts
index cbe73cde0d..df0a352e3b 100644
--- a/__tests__/utils/parse-git-remote-url.test.ts
+++ b/__tests__/utils/parse-git-remote-url.test.ts
@@ -20,6 +20,13 @@ describe("parseGitRemoteUrl", () => {
});
});
+ it("strips the .git suffix when an HTTPS URL has a trailing slash", () => {
+ const result = parseGitRemoteUrl(
+ "https://github.com/OpenHands/OpenHands.git/",
+ );
+ expect(result?.repository).toBe("OpenHands/OpenHands");
+ });
+
it("parses HTTPS GitHub URLs without a .git suffix", () => {
const result = parseGitRemoteUrl("https://github.com/owner/repo");
expect(result?.repository).toBe("owner/repo");
diff --git a/src/utils/parse-git-remote-url.ts b/src/utils/parse-git-remote-url.ts
index 69015049fd..c5b5263599 100644
--- a/src/utils/parse-git-remote-url.ts
+++ b/src/utils/parse-git-remote-url.ts
@@ -44,7 +44,7 @@ function buildParsedGitRemoteUrl(
host: string | null,
rawPath: string,
): ParsedGitRemoteUrl {
- const path = stripGitSuffix(rawPath.replace(/^\/+/, ""));
+ const path = stripGitSuffix(rawPath.replace(/^\/+|\/+$/g, ""));
const provider = detectProvider(host);
const repository =
provider === "azure_devops" ? normalizeAzureDevOpsPath(path) : path;