Skip to content

Commit 61f43e7

Browse files
authored
fix git remote regex parsing to handle additional characters (#1363)
* fix git remote parsing * added test
1 parent 45ab655 commit 61f43e7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/git-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class GitData {
100100
}
101101

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

106106
let port = "443";

tests/git-data.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ const tests = [
7474
project: "package",
7575
},
7676
},
77+
{
78+
input: "https://username-with-dashes:[email protected]:8080/vendor/package.git",
79+
expected: {
80+
schema: "https",
81+
port: "8080",
82+
host: "somegitlab.com",
83+
group: "vendor",
84+
project: "package",
85+
},
86+
},
7787
{
7888
input: "https://example.com:8443/1/2/3package.git",
7989
expected: {

0 commit comments

Comments
 (0)