Skip to content

Commit 11a4e2e

Browse files
committed
Merge branch 'blob-in-path' of github.com:csuich2/git-url-parse into new-version
2 parents 1d4fee2 + b00bdf3 commit 11a4e2e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function gitUrlParse(url) {
162162
const rawIndex = splits.indexOf("raw", 2);
163163
const editIndex = splits.indexOf("edit", 2);
164164
nameIndex = dashIndex > 0 ? dashIndex - 1
165+
: blobIndex > 0 && treeIndex > 0 ? Math.min(blobIndex - 1, treeIndex - 1)
165166
: blobIndex > 0 ? blobIndex - 1
166167
: issuesIndex > 0 ? issuesIndex - 1
167168
: treeIndex > 0 ? treeIndex - 1

test/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,15 @@ tester.describe("parse urls", test => {
521521
test.expect(res.name).toBe("git-url-parse");
522522
test.expect(res.organization).toBe("IonicaBizau");
523523
});
524+
525+
// blob in repo path: https://github.com/IonicaBizau/git-url-parse/issues/167
526+
test.should("handle 'blob' in repo path", () => {
527+
var res = gitUrlParse("https://github.com/owner/id/tree/main/pkg/blob/data.yaml");
528+
test.expect(res.source).toBe("github.com");
529+
test.expect(res.owner).toBe("owner");
530+
test.expect(res.name).toBe("id");
531+
test.expect(res.pathname).toBe("/owner/id/tree/main/pkg/blob/data.yaml");
532+
test.expect(res.filepath).toBe("pkg/blob/data.yaml");
533+
test.expect(res.toString()).toBe("https://github.com/owner/id");
534+
});
524535
});

0 commit comments

Comments
 (0)