More correct regex for github username validation

This commit is contained in:
Sam Boyer 2016-06-08 15:46:38 -04:00
Родитель e7f6c8ba5e
Коммит 4e86ea09d7
2 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -30,7 +30,11 @@ type remoteRepo struct {
// Regexes for the different known import path flavors
var (
ghRegex = regexp.MustCompile(`^(?P<root>github\.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(`^(?P<root>github\.com/([A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`)
ghRegex = regexp.MustCompile(`^(?P<root>github\.com/([A-Za-z0-9][-A-Za-z0-9]+[A-Za-z0-9]/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`)
gpinNewRegex = regexp.MustCompile(`^(?P<root>gopkg\.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(`^(?P<root>gopkg\.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(`^(?P<root>bitbucket\.org/(?P<bitname>[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`)

Просмотреть файл

@ -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{