Skip to content

Commit

Permalink
fix parsing with 'blob' in file path
Browse files Browse the repository at this point in the history
  • Loading branch information
csuich2 committed Jul 8, 2024
1 parent 2882854 commit b00bdf3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit b00bdf3

Please sign in to comment.