diff --git a/detect_github.go b/detect_github.go index 4bf4daf2..b6af9d23 100644 --- a/detect_github.go +++ b/detect_github.go @@ -23,13 +23,17 @@ func (d *GitHubDetector) Detect(src, _ string) (string, bool, error) { } func (d *GitHubDetector) detectHTTP(src string) (string, bool, error) { - parts := strings.Split(src, "/") - if len(parts) < 3 { + parts := strings.Split(src, "?") + if len(parts) > 2 { + return "", false, fmt.Errorf("there is more than 1 '?' in the URL") + } + hostAndPath := parts[0] + hostAndPathParts := strings.Split(hostAndPath, "/") + if len(hostAndPathParts) < 3 { return "", false, fmt.Errorf( "GitHub URLs should be github.com/username/repo") } - - urlStr := fmt.Sprintf("https://%s", strings.Join(parts[:3], "/")) + urlStr := fmt.Sprintf("https://%s", strings.Join(hostAndPathParts[:3], "/")) url, err := url.Parse(urlStr) if err != nil { return "", true, fmt.Errorf("error parsing GitHub URL: %s", err) @@ -39,8 +43,12 @@ func (d *GitHubDetector) detectHTTP(src string) (string, bool, error) { url.Path += ".git" } - if len(parts) > 3 { - url.Path += "//" + strings.Join(parts[3:], "/") + if len(hostAndPathParts) > 3 { + url.Path += "//" + strings.Join(hostAndPathParts[3:], "/") + } + + if len(parts) == 2 { + url.RawQuery = parts[1] } return "git::" + url.String(), true, nil diff --git a/detect_github_test.go b/detect_github_test.go index 70f1c832..196c8dba 100644 --- a/detect_github_test.go +++ b/detect_github_test.go @@ -24,6 +24,10 @@ func TestGitHubDetector(t *testing.T) { "github.com/hashicorp/foo.git?foo=bar", "git::https://github.com/hashicorp/foo.git?foo=bar", }, + { + "github.com/hashicorp/foo.git?foo=bar/foobar,barfoo=bar", + "git::https://github.com/hashicorp/foo.git?foo=bar/foobar,barfoo=bar", + }, } pwd := "/pwd"