From c61016512f8455bf0798623dfdc8e78dac8a9227 Mon Sep 17 00:00:00 2001 From: yhua Date: Wed, 11 Jan 2017 10:39:32 +0800 Subject: [PATCH] fix project name length and follow docker project name rule --- src/ui/api/project.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ui/api/project.go b/src/ui/api/project.go index 7ba50fa3b..ed31dd3df 100644 --- a/src/ui/api/project.go +++ b/src/ui/api/project.go @@ -44,7 +44,8 @@ type projectReq struct { } 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'` // Prepare validates the URL and the user @@ -417,9 +418,9 @@ func isProjectAdmin(userID int, pid int64) bool { func validateProjectReq(req projectReq) error { pn := req.ProjectName 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) if !legal { return fmt.Errorf("project name is not in lower case or contains illegal characters")