Skip to content

Commit ec08266

Browse files
authored
Merge pull request #116 from mroth/alert-autofix-1
Potential fix for code scanning alert no. 1: Incomplete regular expression for hostnames
2 parents cb8cc8e + 5708a67 commit ec08266

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func _detectRemoteURL_LocalGit(path string) (string, error) {
7777
// https://github.com/mroth/bump.git
7878
// git@github.com:mroth/bump.git
7979
func parseGithubRemote(remoteURL string) (owner, repo string, ok bool) {
80-
re := regexp.MustCompile(`^(?:https://|git@)github.com[:/](.*)/(.*?)(?:\.git$|$)`)
80+
re := regexp.MustCompile(`^(?:https://|git@)github\.com[:/](.*)/(.*?)(?:\.git$|$)`)
8181
matches := re.FindStringSubmatch(remoteURL)
8282
if len(matches) < 3 {
8383
return

git_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ func Test_parseGithubRemote(t *testing.T) {
3131
wantRepo: "bump",
3232
wantOk: true,
3333
},
34+
// negative cases: near-miss hostnames should not match
35+
{
36+
name: "nearMiss_HTTPS_dotReplaced",
37+
remoteURL: "https://githubXcom/mroth/bump.git",
38+
wantOk: false,
39+
},
40+
{
41+
name: "nearMiss_SSH_dotReplaced",
42+
remoteURL: "git@githubXcom:mroth/bump.git",
43+
wantOk: false,
44+
},
3445
}
3546
for _, tt := range tests {
3647
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)