diff --git a/remote.go b/remote.go index 659fe00c..65b55320 100644 --- a/remote.go +++ b/remote.go @@ -30,7 +30,11 @@ type remoteRepo struct { // Regexes for the different known import path flavors var ( - ghRegex = regexp.MustCompile(`^(?Pgithub\.com/([A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`) + // This regex allowed some usernames that github currently disallows. They + // may have allowed them in the past, so keeping it in case we need to + // revert. + //ghRegex = regexp.MustCompile(`^(?Pgithub\.com/([A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`) + ghRegex = regexp.MustCompile(`^(?Pgithub\.com/([A-Za-z0-9][-A-Za-z0-9]+[A-Za-z0-9]/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`) gpinNewRegex = regexp.MustCompile(`^(?Pgopkg\.in/(?:([a-zA-Z0-9][-a-zA-Z0-9]+)/)?([a-zA-Z][-.a-zA-Z0-9]*)\.((?:v0|v[1-9][0-9]*)(?:\.0|\.[1-9][0-9]*){0,2}(-unstable)?)(?:\.git)?)((?:/[a-zA-Z0-9][-.a-zA-Z0-9]*)*)$`) //gpinOldRegex = regexp.MustCompile(`^(?Pgopkg\.in/(?:([a-z0-9][-a-z0-9]+)/)?((?:v0|v[1-9][0-9]*)(?:\.0|\.[1-9][0-9]*){0,2}(-unstable)?)/([a-zA-Z][-a-zA-Z0-9]*)(?:\.git)?)((?:/[a-zA-Z][-a-zA-Z0-9]*)*)$`) bbRegex = regexp.MustCompile(`^(?Pbitbucket\.org/(?P[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`) diff --git a/remote_test.go b/remote_test.go index 9578c744..a9117435 100644 --- a/remote_test.go +++ b/remote_test.go @@ -67,6 +67,23 @@ func TestDeduceRemotes(t *testing.T) { VCS: []string{"git"}, }, }, + // some invalid github username patterns + { + "github.com/-sdboyer/vsolver/foo", + nil, + }, + { + "github.com/sdboyer-/vsolver/foo", + nil, + }, + { + "github.com/sdbo.yer/vsolver/foo", + nil, + }, + { + "github.com/sdbo_yer/vsolver/foo", + nil, + }, { "gopkg.in/sdboyer/vsolver.v0", &remoteRepo{