Skip to content

Commit

Permalink
Merge branch 'blob-in-path' of github.com:csuich2/git-url-parse into …
Browse files Browse the repository at this point in the history
…new-version
  • Loading branch information
IonicaBizau committed Jul 15, 2024
2 parents 1d4fee2 + b00bdf3 commit 11a4e2e
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 11a4e2e

Please sign in to comment.