10 // Note that we do not have an SSH-getter currently so this file serves
11 // only to hold the detectSSH helper that is used by other detectors.
13 // sshPattern matches SCP-like SSH patterns (user@host:path)
14 var sshPattern = regexp.MustCompile("^(?:([^@]+)@)?([^:]+):/?(.+)$")
16 // detectSSH determines if the src string matches an SSH-like URL and
17 // converts it into a net.URL compatible string. This returns nil if the
18 // string doesn't match the SSH pattern.
20 // This function is tested indirectly via detect_git_test.go
21 func detectSSH(src string) (*url.URL, error) {
22 matched := sshPattern.FindStringSubmatch(src)
30 qidx := strings.Index(path, "?")
37 u.User = url.User(user)
41 q, err := url.ParseQuery(path[qidx+1:])
43 return nil, fmt.Errorf("error parsing GitHub SSH URL: %s", err)
45 u.RawQuery = q.Encode()