Skip to content

Commit

Permalink
fix git remote regex parsing to handle additional characters (#1363)
Browse files Browse the repository at this point in the history
* fix git remote parsing

* added test
  • Loading branch information
ekohilas authored Oct 7, 2024
1 parent 45ab655 commit 61f43e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/git-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class GitData {
}

if (gitRemote.startsWith("http")) {
gitRemoteMatch = /(?<schema>https?):\/\/(?:(\w+):([\w-]+)@)?(?<host>[^/:]+):?(?<port>\d+)?\/(?<group>\S+)\/(?<project>\S+)\.git/.exec(gitRemote); // regexr.com/7ve8l
gitRemoteMatch = /(?<schema>https?):\/\/(?:([^:]+):([^@]+)@)?(?<host>[^/:]+):?(?<port>\d+)?\/(?<group>\S+)\/(?<project>\S+)\.git/.exec(gitRemote); // regexr.com/7ve8l
assert(gitRemoteMatch?.groups != null, "git remote get-url origin didn't provide valid matches");

let port = "443";
Expand Down
10 changes: 10 additions & 0 deletions tests/git-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ const tests = [
project: "package",
},
},
{
input: "https://username-with-dashes:[email protected]:8080/vendor/package.git",
expected: {
schema: "https",
port: "8080",
host: "somegitlab.com",
group: "vendor",
project: "package",
},
},
{
input: "https://example.com:8443/1/2/3package.git",
expected: {
Expand Down

0 comments on commit 61f43e7

Please sign in to comment.