Merge pull request #1302 from yhua123/dev

LGTM
This commit is contained in:
kun wang 2017-01-11 04:30:10 -06:00 committed by GitHub
commit 733a9fd628

View File

@ -44,7 +44,8 @@ type projectReq struct {
} }
const projectNameMaxLen int = 30 const projectNameMaxLen int = 30
const projectNameMinLen int = 4 const projectNameMinLen int = 2
const restrictedNameChars = `[a-z0-9]+(?:[._-][a-z0-9]+)*`
const dupProjectPattern = `Duplicate entry '\w+' for key 'name'` const dupProjectPattern = `Duplicate entry '\w+' for key 'name'`
// Prepare validates the URL and the user // Prepare validates the URL and the user
@ -417,9 +418,9 @@ func isProjectAdmin(userID int, pid int64) bool {
func validateProjectReq(req projectReq) error { func validateProjectReq(req projectReq) error {
pn := req.ProjectName pn := req.ProjectName
if isIllegalLength(req.ProjectName, projectNameMinLen, projectNameMaxLen) { if isIllegalLength(req.ProjectName, projectNameMinLen, projectNameMaxLen) {
return fmt.Errorf("Project name is illegal in length. (greater than 4 or less than 30)") return fmt.Errorf("Project name is illegal in length. (greater than 2 or less than 30)")
} }
validProjectName := regexp.MustCompile(`^[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*$`) validProjectName := regexp.MustCompile(`^` + restrictedNameChars + `$`)
legal := validProjectName.MatchString(pn) legal := validProjectName.MatchString(pn)
if !legal { if !legal {
return fmt.Errorf("project name is not in lower case or contains illegal characters") return fmt.Errorf("project name is not in lower case or contains illegal characters")