Skip to content

Commit

Permalink
Fix parsing of source with 2 parts SLD
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jul 9, 2018
1 parent e58ee36 commit 13dae80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Expand Up @@ -49,7 +49,7 @@ function gitUrlParse(url) {
};

urlInfo.source = sourceParts.length > 2
? sourceParts.slice(-2).join(".")
? sourceParts.slice(1 - sourceParts.length).join(".")
: urlInfo.source = urlInfo.resource
;

Expand All @@ -60,9 +60,10 @@ function gitUrlParse(url) {
urlInfo.owner = decodeURIComponent(urlInfo.user);

switch (urlInfo.source) {
case "cloudforge.com":
case "git.cloudforge.com":
urlInfo.owner = urlInfo.user;
urlInfo.organization = sourceParts[0];
urlInfo.source = "cloudforge.com";
break;
case "visualstudio.com":
splits = urlInfo.name.split("/");
Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Expand Up @@ -170,6 +170,14 @@ tester.describe("parse urls", test => {
test.expect(res.toString()).toBe("https://companyname.visualstudio.com/DefaultCollection/MyProject/_git/MyRepo");
});

// custom git hosted URL with 2 parts SLD
test.should("parse Gih hosted urls with two parts SLD", () => {
var res = gitUrlParse("https://domain.git.com.cn/owner/name.git");
test.expect(res.source).toBe("git.com.cn");
test.expect(res.owner).toBe("owner");
test.expect(res.name).toBe("name");
});

// Handle URL encoded names of owners and repositories
test.should("https URLs with URL encoded characters", () => {
var res = gitUrlParse("https://companyname.visualstudio.com/My%20Project/_git/My%20Repo");
Expand Down

0 comments on commit 13dae80

Please sign in to comment.