diff --git a/lib/index.js b/lib/index.js index f5e2f76..c5d1045 100644 --- a/lib/index.js +++ b/lib/index.js @@ -162,6 +162,7 @@ function gitUrlParse(url) { const rawIndex = splits.indexOf("raw", 2); const editIndex = splits.indexOf("edit", 2); nameIndex = dashIndex > 0 ? dashIndex - 1 + : blobIndex > 0 && treeIndex > 0 ? Math.min(blobIndex - 1, treeIndex - 1) : blobIndex > 0 ? blobIndex - 1 : issuesIndex > 0 ? issuesIndex - 1 : treeIndex > 0 ? treeIndex - 1 diff --git a/test/index.js b/test/index.js index c0f9db7..0d8a84e 100644 --- a/test/index.js +++ b/test/index.js @@ -521,4 +521,15 @@ tester.describe("parse urls", test => { test.expect(res.name).toBe("git-url-parse"); test.expect(res.organization).toBe("IonicaBizau"); }); + + // blob in repo path: https://github.com/IonicaBizau/git-url-parse/issues/167 + test.should("handle 'blob' in repo path", () => { + var res = gitUrlParse("https://github.com/owner/id/tree/main/pkg/blob/data.yaml"); + test.expect(res.source).toBe("github.com"); + test.expect(res.owner).toBe("owner"); + test.expect(res.name).toBe("id"); + test.expect(res.pathname).toBe("/owner/id/tree/main/pkg/blob/data.yaml"); + test.expect(res.filepath).toBe("pkg/blob/data.yaml"); + test.expect(res.toString()).toBe("https://github.com/owner/id"); + }); });