Skip to content

Commit

Permalink
Fix parsing of git_suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Apr 11, 2018
1 parent b09336e commit 0c215ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Expand Up @@ -48,14 +48,14 @@ function gitUrlParse(url) {
return gitUrlParse.stringify(this, type);
};

const parsedResource = parseDomain(urlInfo.resource)
urlInfo.source = parsedResource ? parsedResource.domain + '.' + parsedResource.tld : urlInfo.resource
const parsedResource = parseDomain(urlInfo.resource);
urlInfo.source = parsedResource ? parsedResource.domain + '.' + parsedResource.tld : urlInfo.resource;

// Note: Some hosting services (e.g. Visual Studio Team Services) allow whitespace characters
// in the repository and owner names so we decode the URL pieces to get the correct result
urlInfo.git_suffix = /\.git$/.test(urlInfo.pathname);
urlInfo.name = decodeURIComponent(urlInfo.pathname.substring(1).replace(/\.git$/, ""));
urlInfo.owner = decodeURIComponent(urlInfo.user);
urlInfo.git_suffix = false;

switch (urlInfo.source) {
case "cloudforge.com":
Expand Down
22 changes: 11 additions & 11 deletions test/index.js
Expand Up @@ -230,20 +230,20 @@ tester.describe("parse urls", test => {
test.expect(res.owner).toBe("a/b/c");
test.expect(res.name).toBe("d");
test.expect(res.href).toBe("git@gitlab.com:a/b/c/d.git");
test.expect(res.toString("https")).toBe("https://gitlab.com/a/b/c/d");
test.expect(res.toString("git+ssh")).toBe("git+ssh://git@gitlab.com/a/b/c/d");
test.expect(res.toString("ssh")).toBe("git@gitlab.com:a/b/c/d");
test.expect(res.toString()).toBe("git@gitlab.com:a/b/c/d");
test.expect(res.toString("https")).toBe("https://gitlab.com/a/b/c/d.git");
test.expect(res.toString("git+ssh")).toBe("git+ssh://git@gitlab.com/a/b/c/d.git");
test.expect(res.toString("ssh")).toBe("git@gitlab.com:a/b/c/d.git");
test.expect(res.toString()).toBe("git@gitlab.com:a/b/c/d.git");
});

test.should("stringify token", () => {
var res = gitUrlParse("https://github.com/owner/name.git");
res.token = "token";
test.expect(res.toString()).toBe("https://token@github.com/owner/name");
test.expect(res.toString()).toBe("https://token@github.com/owner/name.git");

var res = gitUrlParse("https://gitlab.com/group/subgroup/name.git");
res.token = "token";
test.expect(res.toString()).toBe("https://token@gitlab.com/group/subgroup/name");
test.expect(res.toString()).toBe("https://token@gitlab.com/group/subgroup/name.git");

var res = gitUrlParse("https://owner@bitbucket.org/owner/name");
res.token = "token";
Expand All @@ -254,25 +254,25 @@ tester.describe("parse urls", test => {
test.expect(res.toString()).toBe("ssh://git@github.com:22/owner/name");

var res = gitUrlParse("user@github.com:owner/name.git");
test.expect(res.toString()).toBe("user@github.com:owner/name");
test.expect(res.toString()).toBe("user@github.com:owner/name.git");

var res = gitUrlParse("git@github.com:owner/name.git");
res.port = 22;
res.user = "user";
test.expect(res.toString()).toBe("ssh://user@github.com:22/owner/name");
test.expect(res.toString()).toBe("ssh://user@github.com:22/owner/name.git");

var res = gitUrlParse("git+ssh://git@github.com/owner/name.git");
res.port = 22;
res.user = "user";
test.expect(res.toString()).toBe("git+ssh://user@github.com:22/owner/name");
test.expect(res.toString()).toBe("git+ssh://user@github.com:22/owner/name.git");

var res = gitUrlParse("https://github.com/owner/name.git");
res.user = "user";
test.expect(res.toString()).toBe("https://user@github.com/owner/name");
test.expect(res.toString()).toBe("https://user@github.com/owner/name.git");

var res = gitUrlParse("http://github.com/owner/name.git");
res.user = "user";
test.expect(res.toString()).toBe("http://user@github.com/owner/name");
test.expect(res.toString()).toBe("http://user@github.com/owner/name.git");
});

test.it("custom url", () => {
Expand Down

0 comments on commit 0c215ac

Please sign in to comment.