Skip to content

Commit

Permalink
Fix name parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed May 28, 2018
1 parent ff3919e commit 7ee10a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -55,7 +55,7 @@ function gitUrlParse(url) {
// 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.name = decodeURIComponent(urlInfo.pathname.replace(/^\//, '').replace(/\.git$/, ""));
urlInfo.owner = decodeURIComponent(urlInfo.user);

switch (urlInfo.source) {
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Expand Up @@ -11,6 +11,7 @@ const URLS = {
, ftps: "ftps://github.com/IonicaBizau/git-url-parse"
, gitSsh: "git+ssh://git@github.com/IonicaBizau/git-url-parse"
, ref: "https://github.com/IonicaBizau/git-url-parse/blob/master/test/index.js"
, shorthand: "IonicaBizau/git-url-parse"
};

tester.describe("parse urls", test => {
Expand Down Expand Up @@ -201,6 +202,16 @@ tester.describe("parse urls", test => {
test.expect(res.filepath).toBe("test/index.js");
});

// shorthand urls
test.should("parse shorthand urls", () => {
var res = gitUrlParse(URLS.shorthand);
test.expect(res.owner).toBe("IonicaBizau");
test.expect(res.name).toBe("git-url-parse");
test.expect(res.href).toBe(URLS.shorthand);
test.expect(res.full_name).toBe("IonicaBizau/git-url-parse");
test.expect(res.pathname).toBe("IonicaBizau/git-url-parse");
});

test.should("parse subdomains", () => {
var res = gitUrlParse("https://gist.github.com/owner/id");
test.expect(res.source).toBe("github.com");
Expand Down

0 comments on commit 7ee10a6

Please sign in to comment.